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 2 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)
Bruschidy54 marked this conversation as resolved.
Show resolved Hide resolved
[#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
28 changes: 27 additions & 1 deletion Source/swiftlint/Extensions/Configuration+CommandLine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,33 @@ 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
.compactMap { fileConfiguration.rootPath?.bridge().appendingPathComponent($0) }

var shouldSkip = false
Bruschidy54 marked this conversation as resolved.
Show resolved Hide resolved
for excludedPath in excludedPaths {
if file.path?.bridge().pathComponents.starts(with: excludedPath.bridge().pathComponents) ?? false {
shouldSkip = true
break
}
}

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