diff --git a/CHANGELOG.md b/CHANGELOG.md index 4313fb1450..e43631d018 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -121,6 +121,10 @@ #### Bug Fixes +* Fix bug where SwiftLint ignores excluded files list in a nested configuration file. + [Dylan Bruschi](https://github.com/Bruschidy54) + [#2447](https://github.com/realm/SwiftLint/issues/2447) + * Fix false positives on `no_grouping_extension` rule when using `where` clause. [Almaz Ibragimov](https://github.com/almazrafi) diff --git a/Source/swiftlint/Extensions/Configuration+CommandLine.swift b/Source/swiftlint/Extensions/Configuration+CommandLine.swift index 6715af402f..63b73d4e2c 100644 --- a/Source/swiftlint/Extensions/Configuration+CommandLine.swift +++ b/Source/swiftlint/Extensions/Configuration+CommandLine.swift @@ -61,7 +61,29 @@ extension Configuration { let errorMessage = "No lintable files found at paths: '\(visitor.paths.joined(separator: ", "))'" return .failure(.usageError(description: errorMessage)) } - return .success(Dictionary(grouping: files, by: configuration(for:))) + + var groupedFiles = [Configuration: [File]]() + for file in files { + // Files whose configuration specifies they should be excluded will be skipped + let fileConfiguration = configuration(for: file) + let excludedPaths = fileConfiguration.excluded + .map { (fileConfiguration.rootPath ?? "").bridge().appendingPathComponent($0) } + + let shouldSkip: Bool = excludedPaths.contains { + file.path?.bridge().pathComponents.starts(with: $0.bridge().pathComponents) ?? false + } + + if !shouldSkip { + if var configuredFiles = groupedFiles[fileConfiguration] { + configuredFiles.append(file) + groupedFiles[fileConfiguration] = configuredFiles + } else { + groupedFiles[fileConfiguration] = [file] + } + } + } + + return .success(groupedFiles) } private func visit(filesPerConfiguration: [Configuration: [File]],