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

Excluded paths in nested configurations are ignored #2447

Closed
2 tasks done
fixpunkt opened this issue Oct 29, 2018 · 2 comments
Closed
2 tasks done

Excluded paths in nested configurations are ignored #2447

fixpunkt opened this issue Oct 29, 2018 · 2 comments

Comments

@fixpunkt
Copy link

fixpunkt commented Oct 29, 2018

New Issue Checklist

Describe the bug

My example project has this structure:

.
├── .swiftlint.yml
└── A
    ├── .swiftlint.yml
    ├── B
    │   └── Longcat.swift
    └── Hello.swift

./swiftlint.yml is empty, ./A/swiftlint.yml has the following contents:

excluded:
  - B

When I run swiftlint from the project's root directory, Longcat.swift gets linted although it should be excluded.

An explanation as to why I'm trying to do this: We have a common base .swiftlint.yml for our apps, which we symlink from a CocoaPod. Since we need to add project-specific excludes as well (and SwiftLint unfortunately doesn't seem to support shared base configurations at all), I need to mark individual folders as excluded from nested configurations.

Complete output when running SwiftLint, including the stack trace and command used
$ swiftlint lint
Loading configuration from '.swiftlint.yml'
Linting Swift files at paths
Linting 'Longcat.swift' (1/2)
Linting 'Hello.swift' (2/2)
.../swiftlint-example/A/B/Longcat.swift:1: warning: Line Length Violation: Line should be 120 characters or less: currently 189 characters (line_length)
Done linting! Found 1 violation, 0 serious in 2 files.

Environment

  • SwiftLint version (run swiftlint version to be sure)?

0.27.0

  • Installation method used (Homebrew, CocoaPods, building from source, etc)?

In this instance, I was using the swiftlint from brew install swiftlint

  • Paste your configuration file:

See above.

Yes. Toplevel is empty, nested config is the one shown above.

  • Which Xcode version are you using (check xcode-select -p)?

Version 10.0 (10A255)

  • Do you have a sample that shows the issue? Run echo "[string here]" | swiftlint lint --no-cache --use-stdin --enable-all-rules
    to quickly test if your example is really demonstrating the issue. If your example is more
    complex, you can use swiftlint lint --path [file here] --no-cache --enable-all-rules.

I've attached my minimal example project: swiftlint-nested-exclude-example.zip

@realm-probot realm-probot bot added the O:User label Oct 29, 2018
@fixpunkt fixpunkt changed the title excluded paths in nested configurations are ignored Excluded paths in nested configurations are ignored Oct 29, 2018
@ZevEisenberg
Copy link
Contributor

+1 I believe I'm seeing a similar issue.

@Bruschidy54
Copy link
Contributor

I think I found a solution. When SwiftLint is linting files in visitLintableFiles in Configuration+CommandLine, it:

  1. Gathers all lintable files in getFiles. This is where the exclusion of files occurs based on the parent configuration's exclusion list.

  2. These files are grouped by their specific configuration in groupFiles. This is where configurations for each available file are determined (and if nested configurations exist, merged). After these configurations are determined and the files are grouped accordingly, no more files are excluded from the lintable files list, generating the bug where excluded lists of files and directories are ignored in nested configurations.

  3. Finally, each file is visited by the linter.

My solution is to skip files whose merged configurations specify they should be excluded in step 2 or groupFiles. Therefore, they will not be visited in step 3.

Take a look at my PR :)
#2621

jpsim pushed a commit that referenced this issue Apr 7, 2019
Fixes #2447

When SwiftLint is linting files in `visitLintableFiles` in `Configuration+CommandLine`, it:

1. Gathers all lintable files in `getFiles`. This is where the exclusion of files occurs based on the parent configuration's exclusion list.
2. These files are grouped by their specific configuration in `groupFiles`. This is where configurations for each available file are determined (and if nested configurations exist, merged). After these configurations are determined and the files are grouped accordingly, no more files are excluded from the lintable files list. Even though a file's configuration thinks it should be excluded, these files are not removed from the list of lintable files, generating the bug.
3. Finally, each file is visited by the linter.

My solution is to skip files whose merged configurations specify they should be excluded in step 2 or `groupFiles`. Therefore, they will not be visited in step 3.
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

No branches or pull requests

3 participants