Open mildm8nnered opened 1 year ago
I think the relevant logic is here, but maybe there are good reasons for the current behaviour
internal func lintablePaths(
inPath path: String,
forceExclude: Bool,
excludeByPrefix: Bool = false,
fileManager: LintableFileManager = FileManager.default
) -> [String] {
if path.isFile {
if forceExclude {
return excludeByPrefix
? filterExcludedPathsByPrefix(in: [path.absolutePathStandardized()])
: filterExcludedPaths(fileManager: fileManager, in: [path.absolutePathStandardized()])
}
// If path is a file and we're not forcing excludes, skip filtering with excluded/included paths
return [path]
}
let pathsForPath = includedPaths.isEmpty ? fileManager.filesToLint(inPath: path, rootDirectory: nil) : []
let includedPaths = self.includedPaths
.flatMap(Glob.resolveGlob)
.parallelFlatMap { fileManager.filesToLint(inPath: $0, rootDirectory: rootDirectory) }
return excludeByPrefix
? filterExcludedPathsByPrefix(in: pathsForPath, includedPaths)
: filterExcludedPaths(fileManager: fileManager, in: pathsForPath, includedPaths)
}
Am running into this as well.
Please ignore below, that seems to be fixed in main. I had run 0.50.3 locally when I investigated but just built and tested current main and cannot reproduce it.
In addition: the interplay with the --force-exclude
flag doesn't work as expected. Continuing the example 2 above, running swiftlint Source/SwiftLintFramework/Reporters/CSVReporter.swift
will lint just that one file (as expected), but
5. swiftlint --force-exclude Source/SwiftLintFramework/Reporters/CSVReporter.swift
(adding --force-exclude
flag)
~~Expected: Forcing excludes should only ever decrease the number of files matched.
Observed: The path in the argument is ignored and the whole repo is linted. Note that Source
is an included directory and the file is not explicitly excluded.~~
New Issue Checklist
Describe the bug
Consider the case where I have a
.swiftlint.yml
in my project, which specifies someincluded
paths (like SwiftLint's own configuration), and I'm runningswiftlint
on the command line from the top level directory.(
excluded:
can be ignored for the moment).Some of the invocations of
swiftlint
do not work as expected for me. All examples using SwiftLint itself as the project.1)
swiftlint
Expected: Should run swiftlint using the configuration file.
Works as expected (
Linting Swift files in current working directory
could perhaps be clearer, because it's actually linting the files specified in the config).2)
swiftlint Source/SwiftLintFramework/Reporters/CSVReporter.swift
(single file(s))Expected: Should run swiftlint using the configuration file, but only on the specified file(s).
Works as expected:
3)
swiftlint Source/SwiftLintFramework/Reporters/CSVReporter.swift a.swift
(single files, where some do not exist)Expected: Should run
swiftlint
using the configuration file, but only on the specified file(s), and should report any files that do not exist.Observed: SwiftLint lints
Source/SwiftLintFramework/Reporters/CSVReporter.swift
, and then lints all 544 files defined in the configuration (so presumably CSVReporter gets linted twice).And there is an obvious mismatch between
Linting Swift files at paths Source/SwiftLintFramework/Reporters/CSVReporter.swift, a.swift
and what actually happens.4)
swiftlint Source
- directory or directoriesExpected: any swift files under the specified directory or directories will get linted.
Observed: The supplied directories will be ignored, and the files specified in the configuration will be used instead even though
swiftlint
saysLinting Swift files at paths Source
But, if the
included
entries in.swiftlint.yml
are commented out, then the directories specified on the command line will be respected:I think what would be most natural here is that if any paths are supplied on the command line,
swiftlint
should ignoreincluded
from the configuration file, and report any paths that don't actually exist, in a similar way to, for exampleComplete output when running SwiftLint, including the stack trace and command used
See above
Environment
swiftlint version
to be sure)?0.50.3
SwiftLint's own
.swiftlint.yml
filexcodebuild -version
)?See description above.