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

Since 0.41: False positive errors, seems to ignore my .swiftlint.yml #3485

Closed
2 tasks done
freak4pc opened this issue Jan 11, 2021 · 5 comments · Fixed by #3491 or #3542
Closed
2 tasks done

Since 0.41: False positive errors, seems to ignore my .swiftlint.yml #3485

freak4pc opened this issue Jan 11, 2021 · 5 comments · Fixed by #3491 or #3542
Assignees
Labels
bug Unexpected and reproducible misbehavior.

Comments

@freak4pc
Copy link
Contributor

New Issue Checklist

Describe the bug

We've recently updated from 0.39.2 to the latest (0.42) and started getting thousands of errors and warnings in files we excluded with rules we excluded in our config file:

image

I believe this might be related to the fact we're using the --path flag to direct to our config file, like so:

Pods/SwiftLint/swiftlint --path ../

I've tracked this back to 0.41, since running 0.40.3 doesn't exhibit this issue.

Complete output when running swiftlint --path ../

0.41:

Done linting! Found 7123 violations, 2267 serious in 886 files.

0.40.3:

Done linting! Found 3 violations, 0 serious in 321 files.

Environment

  • SwiftLint version (run swiftlint version to be sure)? 0.41
  • Installation method used (Homebrew, CocoaPods, building from source, etc)? CocoaPods
  • Paste your configuration file:

Proprietary, but happy to paste specific portions you think might be an issue.

  • Are you using nested configurations?
    No
  • Which Xcode version are you using (check xcodebuild -version)? 12.3
  • Do you have a sample that shows the issue? I don't - can probably try to figure something out with our structure.
@freak4pc freak4pc changed the title Since 0.41: False positives errors seems to ignore my .swiftlint.yml Since 0.41: False positive errors, seems to ignore my .swiftlint.yml Jan 11, 2021
@fredpi
Copy link
Collaborator

fredpi commented Jan 14, 2021

@freak4pc

I believe this might be related to the fact we're using the --path flag to direct to our config file, like so: Pods/SwiftLint/swiftlint --path ../

Did you mean that you use the --config flag? To specify the location of your config file, the --config argument must be used, while the --path argument is there to specify path(s) of the files to lint. See the help command for all available arguments: swiftlint help lint.

If that isn't the issue and you just confused --path and --config when writing this issue (and I guess so because the command worked with previous versions), would you mind outlining and commenting your raw file structure? As an example:

Folder
    |_ .swiftlint.yml
    |_ ProjectFolder // Within this folder, SwiftLint is called using the command `Pods/SwiftLint/swiftlint --config ../.swiftlint.yml`
        |_ File.swift // This file doesn't respect the disabled rules in the .swiftlint.yml

Thanks in advance!

@freak4pc
Copy link
Contributor Author

freak4pc commented Jan 15, 2021

Thank you @fredpi :)
We actually are using --path ../, and it always worked up until 0.41.

Our structure is basically

Root 
      |_ App
          |__ Pods
          |__ Swiftlint
      |_ Sources
      |_ .swiftlint.yml

I'm running the script from inside App.

My .swiftlint.yml have several included/excluded statements related to these different paths.

included:
  - Sources
excluded:
  - Pods
  - Sources/Core/UI/DesignSystem/TextStyles.swift
  - Sources/Core/UI/DesignSystem/Colors.swift
  - Sources/Core/DI/DependencyInjector+Generated.swift
/// etc etc

When trying other combinations of the flags I'm not getting a result as well:

~ App > Pods/SwiftLint/swiftlint --path ../ --config ../.swiftlint.yml
Linting Swift files at paths ../
No lintable files found at paths: '../'
~ App > Pods/SwiftLint/swiftlint --config ../.swiftlint.yml
Linting Swift files in current working directory
No lintable files found at paths: ''

Happy for any thoughts on your end. We reverted to 0.40.3 for the time being.

@fredpi
Copy link
Collaborator

fredpi commented Jan 15, 2021

@freak4pc Thanks for the detailed information!

The correct command for your use case would be Pods/SwiftLint/swiftlint --path ../ --config ../.swiftlint.yml, because you have to specify the path to your configuration file and specify the path to the files to lint. The command Pods/SwiftLint/swiftlint --path ../ having worked in previous version seems like a lucky coincidence originating from the previous nested configuration implementation (that's been revamped since).

Now, I tried to reproduce why this command doesn't work for you (saying that no lintable files could be found) and figured out that SwiftLint puts the excluded paths that you specified in your .swiftlint.yml in relation to the App folder. That's wrong, as those paths should be relative to the path the .swiftlint.yml resides in: Root.

I will validate if this is indeed the issue and, if true, try to come up with a fix for it.

@fredpi fredpi added the bug Unexpected and reproducible misbehavior. label Jan 15, 2021
@fredpi fredpi self-assigned this Jan 15, 2021
fredpi added a commit to fredpi/SwiftLint that referenced this issue Jan 15, 2021
fredpi added a commit to fredpi/SwiftLint that referenced this issue Jan 15, 2021
@fredpi
Copy link
Collaborator

fredpi commented Jan 15, 2021

@freak4pc #3491 will probably fix this issue. Would you mind trying it out by using the specific branch?

Until the next release is here, here's a funny workaround that I found while fixing this:

  • Add the following line to your .swiftlint.yml: child_config: temp_empty_config.yml
  • Create an empty file called temp_empty_config.yml in the same folder as the .swiftlint.yml file
  • Use the Pods/SwiftLint/swiftlint --path ../ --config ../.swiftlint.yml command (that's also needed when the bugfix is released because the command you were previously using only worked by coincidence)

jpsim pushed a commit that referenced this issue Feb 23, 2021
jpsim pushed a commit that referenced this issue Feb 23, 2021
… parent folder (#3491)

* Add (currently failing) test for #3485

* [#3485] Add missing rootDir adjustment for included / excluded paths

* Add changelog entry

* Adjust tests for relative included / excluded paths
sethfri pushed a commit that referenced this issue Feb 24, 2021
… parent folder (#3491)

* Add (currently failing) test for #3485

* [#3485] Add missing rootDir adjustment for included / excluded paths

* Add changelog entry

* Adjust tests for relative included / excluded paths
@jpsim
Copy link
Collaborator

jpsim commented Feb 25, 2021

I had to revert the fix because it caused other breakages: b66f7c7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Unexpected and reproducible misbehavior.
Projects
None yet
3 participants