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

Fix finding the nested config when a single file path is passed #3342

Merged
merged 3 commits into from
Sep 22, 2020

Conversation

sethfri
Copy link
Contributor

@sethfri sethfri commented Sep 15, 2020

Fixes #3341

When SwiftLint searches for nested configurations and only one file has been passed in via the paths argument, SwiftLint returns early after inadvertently comparing the containing directory of the file-to-be-linted to itself. This happens because rootDirectory is calculated from rootPath, which is set to the file being linted in this scenario.

Package.resolved Outdated Show resolved Hide resolved
@SwiftLintBot
Copy link

SwiftLintBot commented Sep 15, 2020

12 Messages
📖 Linting Aerial with this PR took 1.87s vs 1.91s on master (2% faster)
📖 Linting Alamofire with this PR took 2.7s vs 2.69s on master (0% slower)
📖 Linting Firefox with this PR took 9.17s vs 9.2s on master (0% faster)
📖 Linting Kickstarter with this PR took 15.14s vs 15.24s on master (0% faster)
📖 Linting Moya with this PR took 1.28s vs 1.3s on master (1% faster)
📖 Linting Nimble with this PR took 1.36s vs 1.36s on master (0% slower)
📖 Linting Quick with this PR took 0.7s vs 0.63s on master (11% slower)
📖 Linting Realm with this PR took 2.65s vs 2.67s on master (0% faster)
📖 Linting SourceKitten with this PR took 1.01s vs 1.05s on master (3% faster)
📖 Linting Sourcery with this PR took 7.04s vs 7.16s on master (1% faster)
📖 Linting Swift with this PR took 10.91s vs 10.72s on master (1% slower)
📖 Linting WordPress with this PR took 16.74s vs 16.89s on master (0% faster)

Generated by 🚫 Danger

@sethfri
Copy link
Contributor Author

sethfri commented Sep 17, 2020

This approach turned out not to be a complete fix. I think I have this working a lot better in a branch by completely rewriting the merging algorithm. I'll get the PR updated in the next 24 hours

@sethfri
Copy link
Contributor Author

sethfri commented Sep 18, 2020

Rewriting the merging algorithm wasn't necessary after all. Ended up discovering a much simpler fix. Changes pushed, and I've updated the PR description to reflect the new change.

Part of the problem was rootPath is super confusingly named (it's more of a leaf path). I'll open up a new PR to propose changing the name.

@codecov-commenter
Copy link

codecov-commenter commented Sep 18, 2020

Codecov Report

Merging #3342 into master will decrease coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3342      +/-   ##
==========================================
- Coverage   90.52%   90.51%   -0.02%     
==========================================
  Files         417      417              
  Lines       20434    20432       -2     
==========================================
- Hits        18498    18494       -4     
- Misses       1936     1938       +2     
Impacted Files Coverage Δ
...ntFramework/Extensions/Configuration+Merging.swift 92.59% <100.00%> (+1.21%) ⬆️
...LintFrameworkTests/ConfigurationTests+Nested.swift 97.72% <100.00%> (+0.16%) ⬆️
...rce/SwiftLintFramework/Rules/Style/CommaRule.swift 95.65% <0.00%> (-4.35%) ⬇️
...iftLintFramework/Extensions/String+SwiftLint.swift 94.54% <0.00%> (-1.82%) ⬇️
...tFramework/Rules/Lint/ValidIBInspectableRule.swift 98.64% <0.00%> (-1.36%) ⬇️

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 5e537fa...f5aaeb3. Read the comment docs.

@sethfri
Copy link
Contributor Author

sethfri commented Sep 18, 2020

@jpsim @marcelofabri @keith Sorry for the ping, not sure who to reach out to - just looked at recent PR reviewers. I'm not sure why the buildkite build failed. There doesn't seem to be any info in the log other than

Danger has failed this build.
--
  | Found 1 error.
  | 🚨 Error: The command exited with status 1

Does one of you mind taking a look? 🙏🏻

@sethfri sethfri force-pushed the fixSingleFileNestedConfig branch from 2a290fc to f5aaeb3 Compare September 20, 2020 02:57
@sethfri
Copy link
Contributor Author

sethfri commented Sep 20, 2020

@jpsim @marcelofabri @keith Looks like the CI failure from before was just a flake. Should be good to go here

@jpsim
Copy link
Collaborator

jpsim commented Sep 22, 2020

Thanks for the PR!

@jpsim jpsim merged commit ea06b79 into realm:master Sep 22, 2020
jpsim added a commit that referenced this pull request Sep 22, 2020
jpsim added a commit that referenced this pull request Sep 22, 2020
@sethfri sethfri deleted the fixSingleFileNestedConfig branch September 22, 2020 16:47
optionalendeavors added a commit to optionalendeavors/SwiftLint that referenced this pull request Oct 4, 2020
* master-upstream: (98 commits)
  Fix some false positives in rule `explicit_self` (realm#3368)
  Update SourceKitten to 0.30.1 (realm#3367)
  Fix issues with analyzer rules, Xcode 12 & SwiftUI (realm#3366)
  Add empty changelog section
  release 0.40.3
  Fix false positives for 'multiple_closures_with_trailing_closure' (realm#3353)
  [UnusedDeclarationRule] Work around SR-11985 (realm#3363)
  Revert "Fix finding the nested config when a single file path is passed (realm#3342)" (realm#3362)
  [CONTRIBUTING] Add building & running tips (realm#3360)
  Fix finding the nested config when a single file path is passed (realm#3342)
  Include Linux zip in list of GitHub release binaries (realm#3350)
  [UnusedDeclarationRule] Add more tests (realm#3359)
  Test CI with official Swift 5.3 release (realm#3356)
  Don't mark `@NSApplicationMain` or `@UIApplicationMain` classes as unused (realm#3355)
  [Fix] `UnusedCaptureListRule`: implicit self in @escaping closures (realm#3352)
  Skip correcting files with parser diagnostics (realm#3349)
  [SwiftLintFile] Remove lock in favor of UUID (realm#3347)
  [UnusedDeclarationRule] Speed up and detect more dead code (realm#3340)
  Add empty changelog section
  release 0.40.2
  ...

# Conflicts:
#	Source/swiftlint/Helpers/LintableFilesVisitor.swift
optionalendeavors added a commit to optionalendeavors/SwiftLint that referenced this pull request Oct 4, 2020
* master: (98 commits)
  Fix some false positives in rule `explicit_self` (realm#3368)
  Update SourceKitten to 0.30.1 (realm#3367)
  Fix issues with analyzer rules, Xcode 12 & SwiftUI (realm#3366)
  Add empty changelog section
  release 0.40.3
  Fix false positives for 'multiple_closures_with_trailing_closure' (realm#3353)
  [UnusedDeclarationRule] Work around SR-11985 (realm#3363)
  Revert "Fix finding the nested config when a single file path is passed (realm#3342)" (realm#3362)
  [CONTRIBUTING] Add building & running tips (realm#3360)
  Fix finding the nested config when a single file path is passed (realm#3342)
  Include Linux zip in list of GitHub release binaries (realm#3350)
  [UnusedDeclarationRule] Add more tests (realm#3359)
  Test CI with official Swift 5.3 release (realm#3356)
  Don't mark `@NSApplicationMain` or `@UIApplicationMain` classes as unused (realm#3355)
  [Fix] `UnusedCaptureListRule`: implicit self in @escaping closures (realm#3352)
  Skip correcting files with parser diagnostics (realm#3349)
  [SwiftLintFile] Remove lock in favor of UUID (realm#3347)
  [UnusedDeclarationRule] Speed up and detect more dead code (realm#3340)
  Add empty changelog section
  release 0.40.2
  ...
sethfri added a commit to sethfri/SwiftLint that referenced this pull request Oct 11, 2020
sethfri added a commit to sethfri/SwiftLint that referenced this pull request Oct 26, 2020
sethfri added a commit to sethfri/SwiftLint that referenced this pull request Oct 26, 2020
jpsim pushed a commit to sethfri/SwiftLint that referenced this pull request Nov 8, 2020
jpsim pushed a commit that referenced this pull request Nov 8, 2020
This was previously attempted in #3342, but produced a bug in the case where `--config` is used to specify a config from outside of the source tree. The `--config` argument wasn't always being used as an override, and was being merged with the config in the source tree. This has now been addressed and reverts the revert done in #3362. 

Fixes #3341
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.

SwiftLint doesn't find a nested configuration when one specific file is specified
4 participants