Skip to content

Commit

Permalink
Add all analyzer pseudo-rule (#5519)
Browse files Browse the repository at this point in the history
  • Loading branch information
mildm8nnered authored Apr 2, 2024
1 parent 758c22e commit 8fdf669
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,12 @@
[Martin Redington](https://github.com/mildm8nnered)
[#4858](https://github.com/realm/SwiftLint/issues/4858)

* Add `all` pseudo-rule for `analyzer_rules` - enables all analyzer rules
that are not listed in `disabled_rules`.
[woxtu](https://github.com/woxtu)
[Martin Redington](https://github.com/mildm8nnered)
[#4999](https://github.com/realm/SwiftLint/issues/4999)

## 0.54.0: Macro-Economic Forces

#### Breaking
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,8 @@ Rule inclusion:
* `analyzer_rules`: This is an entirely separate list of rules that are only
run by the `analyze` command. All analyzer rules are opt-in, so this is the
only configurable rule list, there are no equivalents for `disabled_rules`
`only_rules`.
and `only_rules`. The special `all` identifier can also be used here to enable
all analyzer rules, except the ones listed in `disabled_rules`.

```yaml
# By default, SwiftLint uses a set of sensible default rules you can adjust:
Expand Down
14 changes: 12 additions & 2 deletions Source/SwiftLintCore/Extensions/Configuration+RulesMode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,18 @@ public extension Configuration {
effectiveOptInRules = optInRules
}

warnAboutDuplicates(in: effectiveOptInRules + analyzerRules)
self = .default(disabled: Set(disabledRules), optIn: Set(effectiveOptInRules + analyzerRules))
let effectiveAnalyzerRules: [String]
if analyzerRules.contains(RuleIdentifier.all.stringRepresentation) {
let allAnalyzerRules = RuleRegistry.shared.list.list.compactMap { ruleID, ruleType in
ruleType is any AnalyzerRule.Type ? ruleID : nil
}
effectiveAnalyzerRules = allAnalyzerRules
} else {
effectiveAnalyzerRules = analyzerRules
}

warnAboutDuplicates(in: effectiveOptInRules + effectiveAnalyzerRules)
self = .default(disabled: Set(disabledRules), optIn: Set(effectiveOptInRules + effectiveAnalyzerRules))
}
}

Expand Down

0 comments on commit 8fdf669

Please sign in to comment.