Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for globs in excluded paths #2316

Merged
merged 8 commits into from
Jul 30, 2018
Merged

Conversation

keith
Copy link
Collaborator

@keith keith commented Jul 24, 2018

This does not support recursive globs, but it seems like for many cases
plain globs would be enough. This also means we don't need any libraries
to support this case.

@SwiftLintBot
Copy link

SwiftLintBot commented Jul 24, 2018

12 Messages
📖 Linting Aerial with this PR took 0.49s vs 0.38s on master (28% slower)
📖 Linting Alamofire with this PR took 3.54s vs 3.3s on master (7% slower)
📖 Linting Firefox with this PR took 13.9s vs 13.34s on master (4% slower)
📖 Linting Kickstarter with this PR took 25.2s vs 18.72s on master (34% slower)
📖 Linting Moya with this PR took 2.61s vs 2.12s on master (23% slower)
📖 Linting Nimble with this PR took 2.5s vs 1.88s on master (32% slower)
📖 Linting Quick with this PR took 0.64s vs 0.54s on master (18% slower)
📖 Linting Realm with this PR took 4.29s vs 3.32s on master (29% slower)
📖 Linting SourceKitten with this PR took 1.42s vs 1.08s on master (31% slower)
📖 Linting Sourcery with this PR took 6.79s vs 4.72s on master (43% slower)
📖 Linting Swift with this PR took 33.52s vs 28.69s on master (16% slower)
📖 Linting WordPress with this PR took 19.99s vs 17.2s on master (16% slower)

Generated by 🚫 Danger

@keith
Copy link
Collaborator Author

keith commented Jul 24, 2018

Looking at how to fix the test length

@keith
Copy link
Collaborator Author

keith commented Jul 24, 2018

I moved the alias related configuration tests to a new file here to help with the length issue

@keith
Copy link
Collaborator Author

keith commented Jul 24, 2018

Happy to move something else, or do that in a separate PR if needed

@codecov-io
Copy link

codecov-io commented Jul 24, 2018

Codecov Report

Merging #2316 into master will increase coverage by 0.02%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2316      +/-   ##
==========================================
+ Coverage   91.99%   92.01%   +0.02%     
==========================================
  Files         296      299       +3     
  Lines       14886    14936      +50     
==========================================
+ Hits        13694    13744      +50     
  Misses       1192     1192
Impacted Files Coverage Δ
Tests/SwiftLintFrameworkTests/GlobTests.swift 100% <100%> (ø)
...LintFrameworkTests/ConfigurationAliasesTests.swift 100% <100%> (ø)
...s/SwiftLintFrameworkTests/ConfigurationTests.swift 96.53% <100%> (-0.24%) ⬇️
...ework/Extensions/Configuration+LintableFiles.swift 93.33% <100%> (+1.02%) ⬆️
Source/SwiftLintFramework/Helpers/Glob.swift 100% <100%> (ø)
...ce/SwiftLintFramework/Rules/WeakDelegateRule.swift 98.18% <0%> (-1.82%) ⬇️
...SwiftLintFramework/Extensions/File+SwiftLint.swift 96.77% <0%> (-0.47%) ⬇️
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f4add39...8354eee. Read the comment docs.

let includedPaths = included.flatMap {
fileManager.filesToLint(inPath: $0, rootDirectory: rootPath)
}
return (pathsForPath + includedPaths).filter {
!excludedPaths.contains($0)
}
}

private func resolveGlobs(in pattern: String) -> [String] {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it'd be worth it to extract this to a new class and add some tests directly?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left the first test since it's about Configuration calling glob, and added some new glob ones

#endif

return (0..<Int(matchCount)).compactMap { index in
return String(validatingUTF8: globResult.gl_pathv[index]!)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you think about return globResult.gl_pathv[index].flatMap(String.init(validatingUTF8:)) just to avoid any potencial issues?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, but FWIW in this case IMO it's better to crash since this would be breaking the API contract.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had to use it in a closure since it couldn't infer the type otherwise

@keith keith force-pushed the ks/exclude-glob branch 3 times, most recently from 92bdae3 to 144e4bf Compare July 24, 2018 19:39
@marcelofabri
Copy link
Collaborator

This looks good to me from an implementation point of view. We probably should also update the README mentioning this and how to use it.

@keith
Copy link
Collaborator Author

keith commented Jul 26, 2018

Added

@keith keith removed their assignment Jul 27, 2018
@keith
Copy link
Collaborator Author

keith commented Jul 27, 2018

Any other thoughts here @marcelofabri ?

@marcelofabri marcelofabri merged commit 6ea0a5c into master Jul 30, 2018
@marcelofabri marcelofabri deleted the ks/exclude-glob branch July 30, 2018 05:46
@marcelofabri
Copy link
Collaborator

Thanks @keith!

@keith
Copy link
Collaborator Author

keith commented Jul 30, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants