Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
mildm8nnered opened this issue Jan 11, 2023 · 0 comments · Fixed by #4731
Labels
rule-request Requests for a new rules.

Comments

@mildm8nnered
Copy link
Collaborator

mildm8nnered commented Jan 11, 2023

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.

@SimplyDanny SimplyDanny added the rule-request Requests for a new rules. label Jan 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rule-request Requests for a new rules.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants