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

Adds force-exlucde flag to ling/autocorrect commands #2056

Closed
wants to merge 9 commits into from

Conversation

ashfurrow
Copy link
Contributor

@ashfurrow ashfurrow commented Feb 17, 2018

This adds a --force-exclude option to the lint and autocorrect commands which will force SwiftLint to exclude a file if it matches the excluded config options, even if that file is explicitly passed with the --path option.

I could not test locally because I got the following exception:

Fixed this, ran into #1466.
➜  Moya git:(master) ✗ swiftlint
Loading configuration from '.swiftlint.yml'
Fatal error: Loading sourcekitd.framework/Versions/A/sourcekitd failed: file /Users/ashfurrow/SwiftLint/.build/checkouts/SourceKitten.git-6484296299232452758/Source/SourceKittenFramework/library_wrapper.swift, line 61
[1]    71720 illegal hardware instruction  swiftlint

Tested this locally:

➜  Moya git:(master) ✗ swiftlint lint --path Sources/Moya/AnyEncodable.swift --force-exclude --config .swiftlint.yml
Loading configuration from '.swiftlint.yml'
Linting Swift files at path Sources/Moya/AnyEncodable.swift
No lintable files found at path 'Sources/Moya/AnyEncodable.swift'

It fails because it "can't find" any files, but I think that makes sense.

Fixes #2051.

@SwiftLintBot
Copy link

SwiftLintBot commented Feb 17, 2018

1 Error
🚫 Please rebase to get rid of the merge commits in this PR
12 Messages
📖 Linting Aerial with this PR took 0.46s vs 0.41s on master (12% slower)
📖 Linting Alamofire with this PR took 3.65s vs 3.59s on master (1% slower)
📖 Linting Firefox with this PR took 14.0s vs 13.86s on master (1% slower)
📖 Linting Kickstarter with this PR took 21.85s vs 21.32s on master (2% slower)
📖 Linting Moya with this PR took 2.09s vs 2.04s on master (2% slower)
📖 Linting Nimble with this PR took 2.07s vs 2.02s on master (2% slower)
📖 Linting Quick with this PR took 0.6s vs 0.58s on master (3% slower)
📖 Linting Realm with this PR took 3.84s vs 3.79s on master (1% slower)
📖 Linting SourceKitten with this PR took 1.16s vs 1.17s on master (0% faster)
📖 Linting Sourcery with this PR took 5.26s vs 5.22s on master (0% slower)
📖 Linting Swift with this PR took 15.03s vs 14.77s on master (1% slower)
📖 Linting WordPress with this PR took 16.69s vs 16.61s on master (0% slower)

Generated by 🚫 Danger

@codecov-io
Copy link

codecov-io commented Feb 17, 2018

Codecov Report

Merging #2056 into master will decrease coverage by 0.03%.
The diff coverage is 62%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2056      +/-   ##
==========================================
- Coverage   89.69%   89.66%   -0.04%     
==========================================
  Files         256      256              
  Lines       14907    14937      +30     
  Branches      973      973              
==========================================
+ Hits        13371    13393      +22     
- Misses       1519     1526       +7     
- Partials       17       18       +1
Impacted Files Coverage Δ
Source/swiftlint/Commands/AutoCorrectCommand.swift 0% <0%> (ø) ⬆️
...iftlint/Extensions/Configuration+CommandLine.swift 0% <0%> (ø) ⬆️
Source/swiftlint/Commands/LintCommand.swift 0% <0%> (ø) ⬆️
...sts/SwiftLintFrameworkTests/IntegrationTests.swift 37.14% <100%> (ø) ⬆️
...s/SwiftLintFrameworkTests/ConfigurationTests.swift 94.57% <100%> (+0.55%) ⬆️
...ework/Extensions/Configuration+LintableFiles.swift 89.47% <75%> (ø) ⬆️
Source/SwiftLintFramework/Models/Command.swift 95.65% <0%> (-2.18%) ⬇️
...SwiftLintFramework/Extensions/File+SwiftLint.swift 95.09% <0%> (+0.35%) ⬆️

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 dddb0f6...37c413e. Read the comment docs.

@ashfurrow
Copy link
Contributor Author

Okay, got it to run but it's not behaving as I'd expect. Will mark the PR as a WIP.

@ashfurrow ashfurrow changed the title Adds force-exlucde flag to ling/autocorrect commands WIP: Adds force-exlucde flag to ling/autocorrect commands Feb 17, 2018
@ashfurrow ashfurrow changed the title WIP: Adds force-exlucde flag to ling/autocorrect commands Adds force-exlucde flag to ling/autocorrect commands Feb 17, 2018
@ashfurrow
Copy link
Contributor Author

Coooooool, had to brew uninstall swiftlint first. Ready for review 👍

@marcelofabri
Copy link
Collaborator

What should happen if you pass force-exclude and --path ADirectory?

@ashfurrow
Copy link
Contributor Author

That's a good question. I would expect that the other files in the directory would be linted, but any files in excluded would not be. In practice, I just tried this and the file was included. Hmm. I'll do some debugging and let you know how things go.

@marcelofabri
Copy link
Collaborator

@ashfurrow you probably need to filter in https://github.com/realm/SwiftLint/pull/2056/files#diff-27e9905d3d17e50e5263bb7cae0fd09aR24 too.

I'd also make sure that we have tests for what happens if we have force-exclude and:

  • --path aFileThatIsInExcluded
  • --path aFileThatIsNotInExcluded
  • --path aDirectoryThatIsInExcluded
  • --path aDirectoryThatIsNotInExcludedButHasChildrenThatAre

@ashfurrow
Copy link
Contributor Author

Okay so it turns out I didn't quite understand the semantics of how SwiftLint resolves config files. I re-tested your earlier question:

What should happen if you pass force-exclude and --path ADirectory?

This does work as I'd expect: SwiftLint picks up the other files but not the ones in excluded. I tested this with Moya:

swiftlint lint --path .  --force-exclude --config .swiftlint.yml

And this lints everything but does exclude the files in excluded. So it works as-expected. I added the tests you specified too, let me know if there's anything else I can do to wrap this up. And thanks again!

@ashfurrow
Copy link
Contributor Author

Ack! Just saw the failures, will fix.

CHANGELOG.md Outdated
* None.
* Adds `--force-exclude` option to `lint` and `autocorrect` commands, which will
force SwiftLint to exclude files specified in the config `excluded` even if
they are explicitly specified with `--path`.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you add two trailing whitespaces after .?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure can. Would you like a separate PR that checks for these missing spaces using Danger? Could save you some time chasing after contributors 😄

@marcelofabri
Copy link
Collaborator

@ashfurrow Sorry for the delay. This looks good! ✅

Just added a small comment, but other than that and fixing the conflict, this is ready to be merged.

@ashfurrow
Copy link
Contributor Author

Any update on this? I don’t understand the nature of the CI failure.

@marcelofabri
Copy link
Collaborator

@ashfurrow I just manually merged this. I had to rebase to get rid of the merge commit and also I had to run Sourcery to make sure the new tests were being run on Linux (f231e6d).

Thanks and sorry for the delay!

@ashfurrow ashfurrow deleted the force-exclusion branch March 22, 2018 17:10
@ashfurrow
Copy link
Contributor Author

Cool, thanks a lot!

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.

5 participants