Compare commits
1 Commits
main
...
add---corr
Author | SHA1 | Date |
---|---|---|
![]() |
c0bb85310a |
|
@ -8,6 +8,7 @@ internal extension Configuration {
|
|||
public let allRulesWrapped: [ConfigurationRuleWrapper]
|
||||
internal let mode: RulesMode
|
||||
private let aliasResolver: (String) -> String
|
||||
private let correctableOnly: Bool
|
||||
|
||||
private var invalidRuleIdsWarnedAbout: Set<String> = []
|
||||
private var validRuleIdentifiers: Set<String> {
|
||||
|
@ -69,6 +70,10 @@ internal extension Configuration {
|
|||
type(of: $0).description.identifier < type(of: $1).description.identifier
|
||||
}
|
||||
|
||||
if correctableOnly {
|
||||
resultingRules.removeAll { !($0 is CorrectableRule) }
|
||||
}
|
||||
|
||||
// Store & return
|
||||
cachedResultingRules = resultingRules
|
||||
return resultingRules
|
||||
|
@ -99,7 +104,8 @@ internal extension Configuration {
|
|||
mode: RulesMode,
|
||||
allRulesWrapped: [ConfigurationRuleWrapper],
|
||||
aliasResolver: @escaping (String) -> String,
|
||||
originatesFromMergingProcess: Bool = false
|
||||
originatesFromMergingProcess: Bool = false,
|
||||
correctableOnly: Bool
|
||||
) {
|
||||
self.allRulesWrapped = allRulesWrapped
|
||||
self.aliasResolver = aliasResolver
|
||||
|
@ -110,6 +116,7 @@ internal extension Configuration {
|
|||
self.mode = originatesFromMergingProcess
|
||||
? mode
|
||||
: mode.activateCustomRuleIdentifiers(allRulesWrapped: allRulesWrapped)
|
||||
self.correctableOnly = correctableOnly
|
||||
}
|
||||
|
||||
// MARK: - Methods: Validation
|
||||
|
@ -167,7 +174,8 @@ internal extension Configuration {
|
|||
mode: newMode,
|
||||
allRulesWrapped: mergedCustomRules(newAllRulesWrapped: newAllRulesWrapped, with: child),
|
||||
aliasResolver: { child.aliasResolver(self.aliasResolver($0)) },
|
||||
originatesFromMergingProcess: true
|
||||
originatesFromMergingProcess: true,
|
||||
correctableOnly: correctableOnly
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -129,7 +129,8 @@ public struct Configuration {
|
|||
reporter: String = XcodeReporter.identifier,
|
||||
cachePath: String? = nil,
|
||||
pinnedVersion: String? = nil,
|
||||
allowZeroLintableFiles: Bool = false
|
||||
allowZeroLintableFiles: Bool = false,
|
||||
correctableOnly: Bool = false
|
||||
) {
|
||||
if let pinnedVersion = pinnedVersion, pinnedVersion != Version.current.value {
|
||||
queuedPrintError(
|
||||
|
@ -143,7 +144,8 @@ public struct Configuration {
|
|||
rulesWrapper: RulesWrapper(
|
||||
mode: rulesMode,
|
||||
allRulesWrapped: allRulesWrapped ?? (try? ruleList.allRulesWrapped()) ?? [],
|
||||
aliasResolver: { ruleList.identifier(for: $0) ?? $0 }
|
||||
aliasResolver: { ruleList.identifier(for: $0) ?? $0 },
|
||||
correctableOnly: correctableOnly
|
||||
),
|
||||
fileGraph: fileGraph ?? FileGraph(
|
||||
rootDirectory: FileManager.default.currentDirectoryPath.bridge().absolutePathStandardized()
|
||||
|
@ -176,7 +178,8 @@ public struct Configuration {
|
|||
cachePath: String? = nil,
|
||||
ignoreParentAndChildConfigs: Bool = false,
|
||||
mockedNetworkResults: [String: String] = [:],
|
||||
useDefaultConfigOnFailure: Bool? = nil
|
||||
useDefaultConfigOnFailure: Bool? = nil,
|
||||
correctableOnly: Bool = false
|
||||
) {
|
||||
// Handle mocked network results if needed
|
||||
Self.FileGraph.FilePath.mockedNetworkResults = mockedNetworkResults
|
||||
|
@ -224,7 +227,7 @@ public struct Configuration {
|
|||
switch initializationResult {
|
||||
case .initialImplicitFileNotFound:
|
||||
// Silently fall back to default
|
||||
self.init(rulesMode: rulesMode, cachePath: cachePath)
|
||||
self.init(rulesMode: rulesMode, cachePath: cachePath, correctableOnly: correctableOnly)
|
||||
return
|
||||
case .error(let message):
|
||||
errorString = message
|
||||
|
@ -233,7 +236,7 @@ public struct Configuration {
|
|||
if useDefaultConfigOnFailure ?? !hasCustomConfigurationFiles {
|
||||
// No files were explicitly specified, so maybe the user doesn't want a config at all -> warn
|
||||
queuedPrintError("warning: \(errorString) – Falling back to default configuration")
|
||||
self.init(rulesMode: rulesMode, cachePath: cachePath)
|
||||
self.init(rulesMode: rulesMode, cachePath: cachePath, correctableOnly: correctableOnly)
|
||||
} else {
|
||||
// Files that were explicitly specified could not be loaded -> fail
|
||||
queuedPrintError("error: \(errorString)")
|
||||
|
|
|
@ -52,7 +52,8 @@ extension SwiftLint {
|
|||
format: common.format,
|
||||
compilerLogPath: compilerLogPath,
|
||||
compileCommands: compileCommands,
|
||||
inProcessSourcekit: common.inProcessSourcekit
|
||||
inProcessSourcekit: common.inProcessSourcekit,
|
||||
correctableOnly: common.correctableOnly
|
||||
)
|
||||
|
||||
try await LintOrAnalyzeCommand.run(options)
|
||||
|
|
|
@ -56,7 +56,8 @@ extension SwiftLint {
|
|||
format: common.format,
|
||||
compilerLogPath: nil,
|
||||
compileCommands: nil,
|
||||
inProcessSourcekit: common.inProcessSourcekit
|
||||
inProcessSourcekit: common.inProcessSourcekit,
|
||||
correctableOnly: common.correctableOnly
|
||||
)
|
||||
try await LintOrAnalyzeCommand.run(options)
|
||||
}
|
||||
|
|
|
@ -259,7 +259,8 @@ extension Configuration {
|
|||
self.init(
|
||||
configurationFiles: options.configurationFiles,
|
||||
enableAllRules: options.enableAllRules,
|
||||
cachePath: options.cachePath
|
||||
cachePath: options.cachePath,
|
||||
correctableOnly: options.correctableOnly
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,6 +43,8 @@ struct LintOrAnalyzeArguments: ParsableArguments {
|
|||
var output: String?
|
||||
@Flag(help: "Show a live-updating progress bar instead of each file being processed.")
|
||||
var progress = false
|
||||
@Flag(help: "Whether only correctable rules should be applied.")
|
||||
var correctableOnly = false
|
||||
}
|
||||
|
||||
// MARK: - Common Argument Help
|
||||
|
|
|
@ -233,6 +233,7 @@ struct LintOrAnalyzeOptions {
|
|||
let compilerLogPath: String?
|
||||
let compileCommands: String?
|
||||
let inProcessSourcekit: Bool
|
||||
let correctableOnly: Bool
|
||||
|
||||
var verb: String {
|
||||
if autocorrect {
|
||||
|
|
Loading…
Reference in New Issue