You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
SwiftLint doesn't find a nested configuration when one specific file is specified #3341
Assume a file exists called Path/To/My/File.swift, and assume Path/To/My is a directory that contains a .swiftlint.yml file. When you tell SwiftLint to lint only the file, it uses the default configuration instead of the YAML file in Path/To/My.
I believe the root cause is due to these lines, which return the default configuration immediately instead of checking the directory for any configurations.
Complete output when running SwiftLint, including the stack trace and command used
$ swiftlint lint -- Path/To/My/File.swift
Environment
SwiftLint version (run swiftlint version to be sure)? 0.40.2
Installation method used (Homebrew, CocoaPods, building from source, etc)? Homebrew
Which Xcode version are you using (check xcodebuild -version)?
Xcode 11.7
Build version 11E801a
Do you have a sample that shows the issue? Run echo "[string here]" | swiftlint lint --no-cache --use-stdin --enable-all-rules
to quickly test if your example is really demonstrating the issue. If your example is more
complex, you can use swiftlint lint --path [file here] --no-cache --enable-all-rules.
See above.
// This triggers a violation:
letfoo="Test"as!Array
I was incorrect about my hypothesized root cause in the initial description. There were two problems that needed fixing here:
When SwiftLint searches for nested configurations and only one file has been passed in via the paths argument, SwiftLint returns early by inadvertently comparing the containing directory of the file to be linted to itself. This happens because rootDirectory is calculated from rootPath, which is set to the file being linted when there is only one file passed into paths
Even if you fix the early return, SwiftLint will merge the configuration file at the root of the file tree (the configurationPath) with the first configuration it finds starting from the leaf where path is (also confusingly called the rootDirectory). It then returns without doing any other merges. SwiftLint does not seem to handle cascading configurations at multiple levels of a repo.
I've got a fix for this in place, just need to clean it up. Will update #3342 when it's ready
SwiftLint does not seem to handle cascading configurations at multiple levels of a repo
I was mistaken; this actually isn't SwiftLint's intended behavior. This is stated clearly in the README, I just missed it. So (2) above doesn't need to be done, we just need to fix (1). Updating the PR now.
@jpsim Feels like we should open this one back up since the change had to be reverted. I don't seem to have permissions to do that if you wouldn't mind!
Activity
Fix finding the nested config when a single file path is passed
Fix finding the nested config when a single file path is passed
sethfri commentedon Sep 17, 2020
I was incorrect about my hypothesized root cause in the initial description. There were two problems that needed fixing here:
pathsargument, SwiftLint returns early by inadvertently comparing the containing directory of the file to be linted to itself. This happens becauserootDirectoryis calculated fromrootPath, which is set to the file being linted when there is only one file passed intopathsconfigurationPath) with the first configuration it finds starting from the leaf wherepathis (also confusingly called therootDirectory). It then returns without doing any other merges. SwiftLint does not seem to handle cascading configurations at multiple levels of a repo.I've got a fix for this in place, just need to clean it up. Will update #3342 when it's ready
sethfri commentedon Sep 18, 2020
I was mistaken; this actually isn't SwiftLint's intended behavior. This is stated clearly in the README, I just missed it. So (2) above doesn't need to be done, we just need to fix (1). Updating the PR now.
Fix finding a nested config when a single file path is passed
Fix finding a nested config when a single file path is passed
Fix finding the nested config when a single file path is passed (#3342)
sethfri commentedon Sep 25, 2020
@jpsim Feels like we should open this one back up since the change had to be reverted. I don't seem to have permissions to do that if you wouldn't mind!
Fix finding the nested config when a single file path is passed (#3379)