SwiftLint icon indicating copy to clipboard operation
SwiftLint copied to clipboard

Excluded paths in nested configurations seem to resolve to invalid paths

Open dahlborn opened this issue 2 years ago • 3 comments

New Issue Checklist

Describe the bug

Exluded paths in nested configurations currently do not seem to work.

Environment

  • SwiftLint version (run swiftlint version to be sure)? 50.3
  • Installation method used (Homebrew, CocoaPods, building from source, etc)? Building from source and using Homebrew
  • Paste your configuration file:
allow_zero_lintable_files: true
  • Are you using nested configurations? Yes If so, paste their relative paths and respective contents. -> See below
  • Which Xcode version are you using (check xcodebuild -version)? 14.1
  • Do you have a sample that shows the issue?

I created a small Test:

TestFolder
├── .swiftlint.yml
└── SubFolder
    ├── .swiftlint.yml
    └── testFile.swift

yml at TestFolder/.swiftlint.yml

allow_zero_lintable_files: true

yml at TestFolder/SubFolder/.swiflint.yml

disabled_rules:
    - nesting

excluded:
    - testFile.swift

allow_zero_lintable_files: true

Contents of testFile.swift:

import Foundation

struct TestStruct {
    let a = 1
    let b = 2

    struct Nested {
        let c = 3

        struct Nested {
            let d = 4
        }
    }
}

The result being that if SwiftLint is run in TestFolder the file does not get excluded but if it is run in SubFolder it is excluded

I used the debugger with the current master and the excluded paths for the child resolve to TestFolder/SubFolder/SubFolder/testFile.swift instead of TestFolder/SubFolder/testFile.swift which causes the file to not be skipped in Configuration+CommandLine groupFiles. But I don't know if this is caused by a code issue or user error on my side.

dahlborn avatar Feb 13 '23 13:02 dahlborn

+1 on this

From what I get of the readme documentation. Running swiftlint on root directory should work.

› swiftlint                                                                                                                                                    
Linting Swift files in current working directory
Linting 'testFile.swift' (1/1)
/tmp/TestFolder/SubFolder/testFile.swift:4:5: error: Identifier Name Violation: Variable name 'a' should be between 3 and 40 characters long (identifier_name)
/tmp/TestFolder/SubFolder/testFile.swift:5:5: error: Identifier Name Violation: Variable name 'b' should be between 3 and 40 characters long (identifier_name)
/tmp/TestFolder/SubFolder/testFile.swift:8:9: error: Identifier Name Violation: Variable name 'c' should be between 3 and 40 characters long (identifier_name)
/tmp/TestFolder/SubFolder/testFile.swift:11:13: error: Identifier Name Violation: Variable name 'd' should be between 3 and 40 characters long (identifier_name)
Done linting! Found 4 violations, 4 serious in 1 file.

Note that doing: swiftlint --config .swiftlint.yml --config SubFolder/.swiftlint.yml is a workaround and works.

› swiftlint --config .swiftlint.yml --config SubFolder/.swiftlint.yml                                                                                             
Linting Swift files in current working directory
Done linting! Found 0 violations, 0 serious in 0 files.

netbe avatar Jun 28 '23 06:06 netbe

This does not help those using SwiftLint as a plugin

Mordil avatar Aug 04 '23 19:08 Mordil

Same issue in 0.53.0. I tried exactly the same directory structure as per issue https://github.com/realm/SwiftLint/issues/2447 . The issue has been marked as resolved. I guess it's reappearing again?

yehe01 avatar Apr 08 '24 08:04 yehe01