Search code examples
swiftlinterswiftlint

Swiftlint unused_import rule does not work


I am using swiftlint for my project with SPM

I want to use unused_imports rule like this:

...
analyzer_rules:
  - unused_import
...

But it does not find any violations, even thought they are in the project

I have also tried turn it on in the opt-in-rules section

Do you have any ideas, why this could happened?

I am running swiftlint lint --autocorrect


Solution

  • I found the solution

    You need to build your project (or workspace) using xcodebuild tool and save the build logs

    Then you may use it to run swiftLint analyze

    I created this makefile script to do so:

    # Run swiftlint analyze
    lint-analyze:
    make clean
        xcodebuild \
        -project <YOUR_PROJECT>.xcodeproj \
        -scheme <YOUR_SCHEME> \
        -destination 'platform=iOS Simulator,name=iPhone 13 Pro Max,OS=15.5' \
        > xcodebuild.log 
        swiftlint analyze --fix --compiler-log-path xcodebuild.log --quiet
        swiftlint lint --fix --format --quiet