SwiftLint icon indicating copy to clipboard operation
SwiftLint copied to clipboard

Exclude path with directory name

Open ebgraham opened this issue 4 years ago • 8 comments

New Issue Checklist

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.

ebgraham avatar Mar 29 '21 18:03 ebgraham

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.

sethfri avatar May 02 '21 21:05 sethfri

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 #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.

ebgraham avatar May 03 '21 14:05 ebgraham

@jpsim Same issue

jesus-mg-ios avatar Jul 21 '21 17:07 jesus-mg-ios

Hey 👋

Any updates regarding this issue. I still experience the problem on version 0.43.1.

laxmorek avatar Jul 29 '21 11:07 laxmorek

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

sethfri avatar Jul 29 '21 11:07 sethfri

@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:

  1. SwiftLint is using system glob function (on macOS it's Darwin.glob) to resolve files to lint
  2. Darwin.glob is technically POSIX.glob, and POSIX.glob simply doesn't support ** as recursive path wildcard.
  3. 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 of Darwin.glob to make it work properly
  4. #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
  5. 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

el-hoshino avatar Feb 01 '22 13:02 el-hoshino

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/**"

korhancgebologlu avatar May 24 '22 22:05 korhancgebologlu

+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?

stodirascu avatar Dec 19 '22 15:12 stodirascu