SwiftLint icon indicating copy to clipboard operation
SwiftLint copied to clipboard

Rule Request: no_blanket_disables - disallow disabling SwiftLint rules for the entire file

Open mildm8nnered opened this issue 3 years ago • 0 comments

New Issue Checklist

New rule request

  1. Why should this rule be added?

Sometimes it's necessary to disable a SwiftLint rule in code, with the // swiftlint:disable rule_name directive, but engineers intentionally just put the disable at the top of, and applying to the, the entire file, when only a short stretch of code is relevant.

At other times, developers may intend to re-enable the SwiftLint rule, but forget to do so.

In either case, swiftlint rules can end up being disabled for stretches of code that we actually probably do want to lint.

This rule would warn on any cases of // swiftlint:disable rule_name that do not have a matching enable before the end of the file.

  1. Provide several examples of what would and wouldn't trigger violations.

Triggering examples:

// swiftlint:disable some_rule
// swiftlint:disable some_rule some_other_rule
// swiftlint:enable some_rule

Non-triggering examples:

// swiftlint:disable some_rule
// swiftlint:enable some_rule
// swiftlint:disable some_rule some_other_rule
// swiftlint:enable some_rule
// swiftlint:enable some_other_rule
// swiftlint:disable:this some_rule
// swiftlint:disable:previous some_rule
// swiftlint:disable:next some_rule
  1. Should the rule be configurable, if so what parameters should be configurable?

For some rules, such as file_length it doesn't make sense to reenable them.

An allowed_rules parameter would specify rules that will be ignored by this rule.

  1. Should the rule be opt-in or enabled by default? Why? See README.md for guidelines on when to mark a rule as opt-in.

opt-in, as users should never really want to disable rules for irrelevant stretches of code.

mildm8nnered avatar Jan 11 '23 12:01 mildm8nnered