realm/SwiftLint

Xcode plugin ignores "excluded" list from the configuration

Svetoslav opened this issue · 4 comments

New Issue Checklist

Describe the bug

When running SwiftLint through the Xcode SPM plugin and there are excluded paths specified in.swiftlint.yml, SwiftLint lints and shows rule violation warnings for files that should be ignored.

This small project demonstrates the issue: https://github.com/Svetoslav/ExampleProject It has two source files, one of which (ContentView.swift) has a nesting violation (of course, the exact rule does not matter), but it is also excluded in the .swiftlint.yml config.

Complete output when running SwiftLint, including the stack trace and command used

This is the command generated in Xcode and its output (I've replaced the full path to my home folder with ~, but otherwise it is verbatim):

/usr/bin/sandbox-exec -p "(version 1)
(deny default)
(import \"system.sb\")
(allow file-read*)
(allow process*)
(allow file-write*
    (subpath \"/private/tmp\")
    (subpath \"/private/var/folders/pr/88d332n5417gbnmdlq2zz47r0000gn/T\")
)
(deny file-write*
    (subpath \"~/Developer/ExampleProject\")
)
(allow file-write*
    (subpath \"~/Library/Developer/Xcode/DerivedData/ExampleProject-fqnpzeqmzsrgubhfalqfbmtkfuuc/SourcePackages/plugins/ExampleProject.output/ExampleProject/SwiftLintPlugin\")
)
" ~/Library/Developer/Xcode/DerivedData/ExampleProject-fqnpzeqmzsrgubhfalqfbmtkfuuc/SourcePackages/artifacts/swiftlint/SwiftLintBinary.artifactbundle/swiftlint-0.50.3-macos/bin/swiftlint lint --quiet --cache-path ~/Library/Developer/Xcode/DerivedData/ExampleProject-fqnpzeqmzsrgubhfalqfbmtkfuuc/SourcePackages/plugins/ExampleProject.output/ExampleProject/SwiftLintPlugin --config ~/Developer/ExampleProject/.swiftlint.yml ~/Developer/ExampleProject/ExampleProject/ContentView.swift ~/Developer/ExampleProject/ExampleProject/ExampleProjectApp.swift

~/Developer/ExampleProject/ExampleProject/ContentView.swift:5:5: warning: Nesting Violation: Types should be nested at most 1 level deep (nesting)
~/Developer/ExampleProject/ExampleProject/ContentView.swift:5:5: warning: Nesting Violation: Types should be nested at most 1 level deep (nesting)
The folder “Output” doesn’t exist.

Executing the exact same generated command in the terminal does respect the excluded config and does not produce warnings. Here is the output of the command with the --quiet option dropped:

$ ~/Library/Developer/Xcode/DerivedData/ExampleProject-fqnpzeqmzsrgubhfalqfbmtkfuuc/SourcePackages/artifacts/swiftlint/SwiftLintBinary.artifactbundle/swiftlint-0.50.3-macos/bin/swiftlint lint --cache-path ~/Library/Developer/Xcode/DerivedData/ExampleProject-fqnpzeqmzsrgubhfalqfbmtkfuuc/SourcePackages/plugins/ExampleProject.output/ExampleProject/SwiftLintPlugin --config ~/Developer/ExampleProject/.swiftlint.yml ~/Developer/ExampleProject/ExampleProject/ContentView.swift ~/Developer/ExampleProject/ExampleProject/ExampleProjectApp.swift
Linting Swift files at paths ~/Developer/ExampleProject/ExampleProject/ContentView.swift, ~/Developer/ExampleProject/ExampleProject/ExampleProjectApp.swift
Linting 'ExampleProjectApp.swift' (1/1)
Done linting! Found 0 violations, 0 serious in 1 file.

Environment

  • SwiftLint version (run swiftlint version to be sure)?
    0.50.3
  • Installation method used (Homebrew, CocoaPods, building from source, etc)?
    SPM
  • Paste your configuration file:
excluded:
  - ExampleProject/ContentView.swift
  • Are you using nested configurations?
    If so, paste their relative paths and respective contents.
    No, I'm not using nested configurations.
  • Which Xcode version are you using (check xcodebuild -version)?
    Xcode 14.2, Build version 14C18
  • 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.
    See the linked repo above.

I'm having the same issue with the plugin ignoring the disabled_rules I've set up in the .swiftlint.yml file, even though it is in the project root.

And have you managed to run autocorrect with the build plugin ? I just get warnings on my side

Your issue might have been resolved with #4757, @Svetoslav. Can you confirm?

Note that the fix has not yet been released, though.

@SimplyDanny Yes, #4757 seems to have resolved the issue. All projects in which I've had false-positives from disabled files lint correctly with both cfd9a26 and most recent main head. Cheers! 🎉