diff --git a/CHANGELOG.md b/CHANGELOG.md index 0755c814aa..df1b3b9993 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,11 @@ (e.g. `@testable`, `@_exported`, ...). [hiltonc](https://github.com/hiltonc) +* Add new `--quiet-deprecation-warnings` flag that silences deprecation + warnings that would otherwise be printed to the console. + [SimplyDanny](https://github.com/SimplyDanny) + [#4989](https://github.com/realm/SwiftLint/issues/4989) + * Do not trigger `redundant_self_in_closure` rule when another idenfier `x` in scope shadows the field accessed by `self.x` to avoid semantical changes. [SimplyDanny](https://github.com/SimplyDanny) diff --git a/Source/SwiftLintCore/Models/Issue.swift b/Source/SwiftLintCore/Models/Issue.swift index b0f937fbb1..600cbd8b01 100644 --- a/Source/SwiftLintCore/Models/Issue.swift +++ b/Source/SwiftLintCore/Models/Issue.swift @@ -47,6 +47,9 @@ public enum Issue: LocalizedError, Equatable { /// An error that occurred when parsing YAML. case yamlParsing(String) + /// Flag to enable warnings for deprecations being printed to the console. Printing is enabled by default. + public static var printDeprecationWarnings = true + /// Wraps any `Error` into a `SwiftLintError.genericWarning` if it is not already a `SwiftLintError`. /// /// - parameter error: Any `Error`. @@ -75,6 +78,9 @@ public enum Issue: LocalizedError, Equatable { /// Print the issue to the console. public func print() { + if case .ruleDeprecated = self, !Self.printDeprecationWarnings { + return + } queuedPrintError(errorDescription) } diff --git a/Source/swiftlint/Commands/Lint.swift b/Source/swiftlint/Commands/Lint.swift index ea9dac52dc..b6f39fd33e 100644 --- a/Source/swiftlint/Commands/Lint.swift +++ b/Source/swiftlint/Commands/Lint.swift @@ -13,6 +13,8 @@ extension SwiftLint { var useSTDIN = false @Flag(help: quietOptionDescription(for: .lint)) var quiet = false + @Flag(help: "Don't print deprecation warnings.") + var silenceDeprecationWarnings = false @Option(help: "The directory of the cache used when linting.") var cachePath: String? @Flag(help: "Ignore cache when linting.") @@ -23,6 +25,8 @@ extension SwiftLint { var paths = [String]() func run() async throws { + Issue.printDeprecationWarnings = !silenceDeprecationWarnings + let allPaths: [String] if let path { // TODO: [06/14/2024] Remove deprecation warning after ~2 years.