SwiftLint icon indicating copy to clipboard operation
SwiftLint copied to clipboard

"excluded" parameter handling changed in 0.43.0

Open Cyberbeni opened this issue 3 years ago • 7 comments

New Issue Checklist

Describe the bug

We have this exclusion in .swiftlint.yml and it was working in 0.42.0 but after upgrading to 0.43.0, code inside that directory is producing warnings.

excluded:
  - Utils/3rdParty

Changing this to either path/from/git/root/Utils/3rdParty solves the issue.

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

we have this script in our Xcode build phases:

ROOT_DIR="$(git rev-parse --show-toplevel)"
# using default lint rules if not overridden for the project
ln -s "$ROOT_DIR/.swiftlint.yml" "$SRCROOT/.swiftlint.yml"
"$($BREW --prefix)/bin/swiftlint" --path "$SRCROOT"

Environment

  • SwiftLint version (run swiftlint version to be sure)?
    • 0.43.0
  • Installation method used (Homebrew, CocoaPods, building from source, etc)?
    • Homebrew
  • Paste your configuration file:
excluded:
  - Utils/3rdParty
  • Are you using nested configurations? If so, paste their relative paths and respective contents.
    • No
  • Which Xcode version are you using (check xcodebuild -version)?
    • 12.4
  • 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.
    • No

Edit: This is on an M1 MacBook, don't know if that matters.

Cyberbeni avatar Mar 04 '21 13:03 Cyberbeni

From the 0.43.0 release notes:

Configuration files now consistently have their included/excluded relative file paths applied relative to their location in the file system. Previously the root configuration file applied these relative to the current working directory, but nested configurations applied these to their location in the file system.

Note that the config file supports environment variables, so if you need to specify a path relative to the current working directory, you can use ${PWD}.

So, this might work in your config:

excluded:
  - ${PWD}/Utils/3rdParty

g-mark avatar Mar 04 '21 13:03 g-mark

@g-mark is correct, this was a deliberate breaking change, one that was carefully weighed and discussed here: https://github.com/realm/SwiftLint/pull/3491#issuecomment-786277770

jpsim avatar Mar 04 '21 14:03 jpsim

I had forgotten that we support environment variables in the configuration file, thanks for the reminder @g-mark!

jpsim avatar Mar 04 '21 14:03 jpsim

Thanks for the clarification.

As you can see in our example, the build phase symlinks to a single .swiftlint.yml as most projects need the same rules. Is it intentional that in this case, the paths are still relative to the original file and not the symlink, that is picked up as the configuration file? If it's intentional then this issue can be closed.

Cyberbeni avatar Mar 04 '21 15:03 Cyberbeni

I think that's intentional. I'd be curious to know if @fredpi has strong opinions here.

jpsim avatar Mar 04 '21 15:03 jpsim

I've noticed something interesting related to exclude path handling that differs between the SwiftLint docker image and the macOS installed binary (both version 0.46.5).

We have the SwiftLint config in the location scripts/config/swiftlint and there is a symlink in the root of our project to this file .swiftlint.yml -> scripts/config/swiftlint. We have some exclusion rules declared in this file, eg:

excluded: 
    - .build
    - Carthage
    - Pods

When running SwiftLint on macOS with this symlink in place the exclusion rules are correctly applied. When running it in Docker (using docker run -it -v `pwd`:`pwd` -w `pwd` ghcr.io/realm/swiftlint:latest) they are not. Even when I run sh to get an interactive shell in the docker container and run SwiftLint directly in Linux I get the same behaviour.

The working directory is the same. SwiftLint is invoked at the root of the project and the config file appears to be loaded (our rule customisations are applied).

When I delete the symlink and copy the SwiftLint config out of the scripts/config folder into the root of the project (as .swiftlint.yml) the behaviour between Docker and macOS is the same (exclusions are correctly applied).

I've tried adding ${PWD} in front of the exclude paths in the config file to no effect.

Perhaps the handling of paths is different between docker and macOS?

orj avatar Mar 23 '22 22:03 orj

@orj could you please file a new issue? I think you’re seeing something other than what was reported in this thread.

jpsim avatar Mar 24 '22 00:03 jpsim