diff --git a/CHANGELOG.md b/CHANGELOG.md index 3149c5480e..7570b55ca1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,10 @@ #### Breaking -* None. +* Changed behavior of `strict` option on `lint` and `analyze` to treat + all warnings as errors instead of only changing the exit code. + [Jeehut](https://github.com/Jeehut) + [#3312](https://github.com/realm/SwiftLint/issues/3312) #### Experimental @@ -200,11 +203,11 @@ [Marcelo Fabri](https://github.com/marcelofabri) [#3225](https://github.com/realm/SwiftLint/issues/3225) -* Fix some cases where the output would be incomplete when running +* Fix some cases where the output would be incomplete when running SwiftLint on Linux. [Marcelo Fabri](https://github.com/marcelofabri) [#3214](https://github.com/realm/SwiftLint/issues/3214) - + * `compiler_protocol_init` now triggers on `IndexSet(arrayLiteral:)`. [Janak Shah](https://github.com/janakshah) [#3284](https://github.com/realm/SwiftLint/pull/3284) @@ -244,7 +247,7 @@ This is the last release to support building with Swift 5.0.x. [Marcelo Fabri](https://github.com/marcelofabri) [#3149](https://github.com/realm/SwiftLint/issues/3149) -* Fix false positives in `redundant_objc_attribute` rule in extensions when +* Fix false positives in `redundant_objc_attribute` rule in extensions when using Swift 5.2. [Marcelo Fabri](https://github.com/marcelofabri) @@ -371,7 +374,7 @@ This is the last release to support building with Swift 5.0.x. * Fix false positives when line ends with carriage return + line feed. [John Mueller](https://github.com/john-mueller) [#3060](https://github.com/realm/SwiftLint/issues/3060) - + * Implicit_return description now reports current config correctly. [John Buckley](https://github.com/nhojb) diff --git a/Source/swiftlint/Commands/AnalyzeCommand.swift b/Source/swiftlint/Commands/AnalyzeCommand.swift index ff633a9c26..97c8e37efa 100644 --- a/Source/swiftlint/Commands/AnalyzeCommand.swift +++ b/Source/swiftlint/Commands/AnalyzeCommand.swift @@ -69,7 +69,7 @@ struct AnalyzeOptions: OptionsProtocol { <*> mode <| pathOption(action: "analyze") <*> mode <| configOption <*> mode <| Option(key: "strict", defaultValue: false, - usage: "fail on warnings") + usage: "upgrades warnings to serious violations (errors)") <*> mode <| Option(key: "lenient", defaultValue: false, usage: "downgrades serious violations to warnings, warning threshold is disabled") <*> mode <| Option(key: "force-exclude", defaultValue: false, diff --git a/Source/swiftlint/Commands/LintCommand.swift b/Source/swiftlint/Commands/LintCommand.swift index f9b26be9ea..47414c04c5 100644 --- a/Source/swiftlint/Commands/LintCommand.swift +++ b/Source/swiftlint/Commands/LintCommand.swift @@ -45,7 +45,7 @@ struct LintOptions: OptionsProtocol { usage: "lint standard input") <*> mode <| configOption <*> mode <| Option(key: "strict", defaultValue: false, - usage: "fail on warnings") + usage: "upgrades warnings to serious violations (errors)") <*> mode <| Option(key: "lenient", defaultValue: false, usage: "downgrades serious violations to warnings, warning threshold is disabled") <*> mode <| Option(key: "force-exclude", defaultValue: false, diff --git a/Source/swiftlint/Helpers/LintOrAnalyzeCommand.swift b/Source/swiftlint/Helpers/LintOrAnalyzeCommand.swift index 4e487d6549..acdc1f6cfe 100644 --- a/Source/swiftlint/Helpers/LintOrAnalyzeCommand.swift +++ b/Source/swiftlint/Helpers/LintOrAnalyzeCommand.swift @@ -62,21 +62,11 @@ struct LintOrAnalyzeCommand { ruleBenchmark.save() } try? cache?.save() - return successOrExit(numberOfSeriousViolations: numberOfSeriousViolations, - strictWithViolations: options.strict && !violations.isEmpty) + guard numberOfSeriousViolations == 0 else { exit(2) } + return .success(()) } } - private static func successOrExit(numberOfSeriousViolations: Int, - strictWithViolations: Bool) -> Result<(), CommandantError<()>> { - if numberOfSeriousViolations > 0 { - exit(2) - } else if strictWithViolations { - exit(3) - } - return .success(()) - } - private static func printStatus(violations: [StyleViolation], files: [SwiftLintFile], serious: Int, verb: String) { let pluralSuffix = { (collection: [Any]) -> String in return collection.count != 1 ? "s" : "" @@ -109,15 +99,30 @@ struct LintOrAnalyzeCommand { } private static func applyLeniency(options: LintOrAnalyzeOptions, violations: [StyleViolation]) -> [StyleViolation] { - if !options.lenient { + switch (options.lenient, options.strict) { + case (false, false): return violations - } - return violations.map { - if $0.severity == .error { - return $0.with(severity: .warning) - } else { - return $0 + + case (true, false): + return violations.map { + if $0.severity == .error { + return $0.with(severity: .warning) + } else { + return $0 + } } + + case (false, true): + return violations.map { + if $0.severity == .warning { + return $0.with(severity: .error) + } else { + return $0 + } + } + + case (true, true): + queuedFatalError("Invalid command line options: 'lenient' and 'strict' are mutually exclusive.") } } }