Processing of command line paths is unintuitive and confusing
Nobody has claimed this yet.
- Dominant language
- Swift
- Stars
- 19.7k
- Forks
- 2.3k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 11
Description
New Issue Checklist
- Updated SwiftLint to the latest version
- I searched for existing GitHub issues
Describe the bug
Consider the case where I have a .swiftlint.yml in my project, which specifies some included paths (like SwiftLint's own configuration), and I'm running swiftlint on the command line from the top level directory.
% head .swiftlint.yml
included:
- Plugins
- Source
- Tests
excluded:
- Tests/SwiftLintFrameworkTests/Resources
analyzer_rules:
- unused_declaration
- unused_import
opt_in_rules:
(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.
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).
% swiftlint
Linting Swift files in current working directory
Linting 'SwiftLintPlugin.swift' (1/544)
Linting 'Path+Helpers.swift' (2/544)
Linting 'BodyLengthRuleVisitor.swift' (3/544)
Linting 'CommandVisitor.swift' (4/544)
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:
% swiftlint Source/SwiftLintFramework/Reporters/CSVReporter.swift
Linting Swift files at paths Source/SwiftLintFramework/Reporters/CSVReporter.swift
Linting 'CSVReporter.swift' (1/1)
Done linting! Found 0 violations, 0 serious in 1 file.
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.
% swiftlint Source/SwiftLintFramework/Reporters/CSVReporter.swift a.swift
Linting Swift files at paths Source/SwiftLintFramework/Reporters/CSVReporter.swift, a.swift
Linting 'SwiftLintPlugin.swift' (1/545)
Linting 'Path+Helpers.swift' (2/545)
Linting 'Source/SwiftLintFramework/Reporters/CSVReporter.swift' (3/545)
Linting 'BodyLengthRuleVisitor.swift' (4/545)
swiftlint Source- directory or directories
Expected: 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 says Linting Swift files at paths Source
% swiftlint Source
Linting Swift files at paths Source
Linting 'SwiftLintPlugin.swift' (1/544)
Linting 'Path+Helpers.swift' (2/544)
Linting 'BodyLengthRuleVisitor.swift' (3/544)
But, if the included entries in .swiftlint.yml are commented out, then the directories specified on the command line will be respected:
% swiftlint Source
Linting Swift files at paths Source
Linting 'BodyLengthRuleVisitor.swift' (1/446)
Linting 'RuleListDocumentation.swift' (2/446)
Linting 'RuleDocumentation.swift' (4/446)
I think what would be most natural here is that if any paths are supplied on the command line, swiftlint should ignore included from the configuration file, and report any paths that don't actually exist, in a similar way to, for example
% ls -l Gemfile Gemfile.nope
ls: Gemfile.nope: No such file or directory
-rw-r--r-- 1 martin.redington staff 72 16 Oct 17:50 Gemfile
Complete output when running SwiftLint, including the stack trace and command used
See above
Environment
- SwiftLint version (run
swiftlint versionto be sure)?0.50.3 - Installation method used (Homebrew, CocoaPods, building from source, etc)? homebrew
- Paste your configuration file:
SwiftLint's own .swiftlint.yml file
- Are you using nested configurations? No
- Which Xcode version are you using (check
xcodebuild -version)?
Xcode 14.2
Build version 14C18
- Do you have a sample that shows the issue?
See description above.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the documented swiftlint invocations with configured included paths, especially the mixed-file and directory cases. Trace the command-line path handling and configuration interaction; done means explicit paths are honored, missing paths are reported, and the status output matches the files actually linted.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- cli, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100