From 8fdf669d53f7d51aeb0e6f03b9d4afa1ed3da359 Mon Sep 17 00:00:00 2001 From: Martin Redington Date: Tue, 2 Apr 2024 08:34:17 +0100 Subject: [PATCH] Add `all` analyzer pseudo-rule (#5519) --- CHANGELOG.md | 6 ++++++ README.md | 3 ++- .../Extensions/Configuration+RulesMode.swift | 14 ++++++++++++-- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 77fddc3f2c..5fc00ff80c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index ae15b1c192..3abca7de11 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/Source/SwiftLintCore/Extensions/Configuration+RulesMode.swift b/Source/SwiftLintCore/Extensions/Configuration+RulesMode.swift index 0bc021705c..71de532588 100644 --- a/Source/SwiftLintCore/Extensions/Configuration+RulesMode.swift +++ b/Source/SwiftLintCore/Extensions/Configuration+RulesMode.swift @@ -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)) } }