Skip to content

Commit

Permalink
Add new --silence-deprecation-warnings flag
Browse files Browse the repository at this point in the history
  • Loading branch information
SimplyDanny committed Jun 20, 2023
1 parent 21fbf59 commit 25c8501
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions Source/SwiftLintCore/Models/Issue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down Expand Up @@ -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)
}

Expand Down
4 changes: 4 additions & 0 deletions Source/swiftlint/Commands/Lint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand All @@ -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.
Expand Down

0 comments on commit 25c8501

Please sign in to comment.