Exclude path with directory name
New Issue Checklist
- [x] Updated SwiftLint to the latest version
- [x] I searched for existing GitHub issues
Describe the bug
There is current wildcard functionality for excluded paths (https://github.com/realm/SwiftLint/issues/1220 | https://github.com/realm/SwiftLint/pull/2316/files), but it doesn't seem to work for matching directory name in along any path (or I am using regex exclusions incorrectly).
I'd like be able to exclude any source file along a path with a directory matching a given name. E.g., I want to exclude anything in a "Tests" folder (or sub-folder), something along the lines of
excluded:
- "**/Tests/**"
Am I using this wrong or is this not supported? I've tried many iterations without success.
Hi @ebgraham, how are you running SwiftLint? If you're just running the swiftlint command by itself from the root directory, I'd expect this to work. If you're passing in individual files, you might be running into the behavior I'm trying to fix in https://github.com/realm/SwiftLint/pull/3534. I haven't been able to make much progress on that PR recently, so feel free to help if you have any time.
Hi @ebgraham, how are you running SwiftLint? If you're just running the
swiftlintcommand by itself from the root directory, I'd expect this to work. If you're passing in individual files, you might be running into the behavior I'm trying to fix in #3534. I haven't been able to make much progress on that PR recently, so feel free to help if you have any time.
I'm running it from the root directory, but doesn't work.
@jpsim Same issue
Hey 👋
Any updates regarding this issue. I still experience the problem on version 0.43.1.
If anyone wants to help with the fix for this issue, this is where the PR is currently blocked: https://github.com/realm/SwiftLint/pull/3534#issuecomment-830863143
@jpsim Hi. I tried to fix this problem but found it's far more complicated than I thought.
Here's what this issue exactly is and why #3534 doesn't work as expected:
- SwiftLint is using system glob function (on macOS it's
Darwin.glob) to resolve files to lint Darwin.globis technically POSIX.glob, and POSIX.glob simply doesn't support**as recursive path wildcard.- So if we want to use
**as recursive path wildcard, we need to either a) implement our own functions to do it, or b) implicitly use custom shells like zsh instead ofDarwin.globto make it work properly - #3534 isn't resolving files at first place, but rather try to exclude each single file when applying lint configurations to it, which could be very expensive if there's a lot of files in a directory
- After we somehow fixed this issue, we should also fix this test (I guess this test is intended to be like this at present)
p.s. I found that this issue explains some more details 😄 #3789
Hi,
I do not have the same issue with the latest version 47.1.0 . However, Similar excluded path does not work for the custom rule. When I move the excluded path from custom rule excluded to general excluded, the warnings are disappearing.
custom_rules: discouraged_optional_boolean_ModelFiles: regex: "Bool\?" excluded: - "**/Model/**"
+1 one for fixing this. Our tests are spread out across modules, each under their own /Tests subfolder.
Is there any way to support this scenario today? Like using regex e.g. in the excluded directive?