mirror of
https://github.com/realm/SwiftLint.git
synced 2026-06-06 20:18:40 +00:00
Add support for params files for file path arguments
This allows you to pass `@path/to/file` which will be read line by line for the list of files to lint / analyze. This is useful if you want to pass a massive list of files which will either exceed arg max, or break most unix tools if you use script input files + env vars.
This commit is contained in:
+2
-1
@@ -10,7 +10,8 @@
|
||||
|
||||
#### Enhancements
|
||||
|
||||
* None.
|
||||
* Add support for params files for file paths.
|
||||
[keith](https://github.com/keith)
|
||||
|
||||
#### Bug Fixes
|
||||
|
||||
|
||||
@@ -28,6 +28,16 @@ enum LintOrAnalyzeModeWithCompilerArguments {
|
||||
case analyze(allCompilerInvocations: CompilerInvocations)
|
||||
}
|
||||
|
||||
private func resolveParamsFiles(args: [String]) -> [String] {
|
||||
return args.reduce(into: []) { allArgs, arg in
|
||||
if arg.hasPrefix("@"), let contents = try? String(contentsOfFile: String(arg.dropFirst())) {
|
||||
allArgs += resolveParamsFiles(args: contents.split(separator: "\n").map(String.init))
|
||||
} else if !arg.isEmpty {
|
||||
allArgs.append(arg)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct LintableFilesVisitor {
|
||||
let paths: [String]
|
||||
let action: String
|
||||
@@ -44,7 +54,7 @@ struct LintableFilesVisitor {
|
||||
init(paths: [String], action: String, useSTDIN: Bool, quiet: Bool, useScriptInputFiles: Bool, forceExclude: Bool,
|
||||
cache: LinterCache?, parallel: Bool,
|
||||
allowZeroLintableFiles: Bool, block: @escaping (CollectedLinter) -> Void) {
|
||||
self.paths = paths
|
||||
self.paths = resolveParamsFiles(args: paths)
|
||||
self.action = action
|
||||
self.useSTDIN = useSTDIN
|
||||
self.quiet = quiet
|
||||
@@ -61,7 +71,7 @@ struct LintableFilesVisitor {
|
||||
useScriptInputFiles: Bool, forceExclude: Bool,
|
||||
cache: LinterCache?, compilerInvocations: CompilerInvocations?,
|
||||
allowZeroLintableFiles: Bool, block: @escaping (CollectedLinter) -> Void) {
|
||||
self.paths = paths
|
||||
self.paths = resolveParamsFiles(args: paths)
|
||||
self.action = action
|
||||
self.useSTDIN = useSTDIN
|
||||
self.quiet = quiet
|
||||
|
||||
Reference in New Issue
Block a user