Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug where nested configuration excluded files are ignored #2648

Merged
merged 5 commits into from
Apr 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,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)
Expand Down
24 changes: 23 additions & 1 deletion Source/swiftlint/Extensions/Configuration+CommandLine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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]],
Expand Down