Print a warning for Analyzer rules misplaced in the configuration (#4620)

This commit is contained in:
Danny Mösch 2022-12-06 00:03:54 +01:00 committed by GitHub
parent 93d0d8fa7f
commit 4adabd8e4b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 0 deletions

View File

@ -32,6 +32,11 @@
[Martin Redington](https://github.com/mildm8nnered)
[#4200](https://github.com/realm/SwiftLint/issues/4200)
* Show warnings in the console for Analyzer rules that are listed in the
`opt_in_rules` configuration section.
[SimplyDanny](https://github.com/SimplyDanny)
[#4612](https://github.com/realm/SwiftLint/issues/4612)
#### Bug Fixes
* Fix configuration parsing error in `unused_declaration` rule.

View File

@ -57,6 +57,7 @@ extension Configuration {
configurationDictionary: dict, disabledRules: disabledRules,
optInRules: optInRules, onlyRules: onlyRules, ruleList: ruleList
)
Self.warnAboutMisplacedAnalyzerRules(optInRules: optInRules, ruleList: ruleList)
let allRulesWrapped: [ConfigurationRuleWrapper]
do {
@ -202,4 +203,18 @@ extension Configuration {
}
}
}
private static func warnAboutMisplacedAnalyzerRules(optInRules: [String], ruleList: RuleList) {
let analyzerRules = ruleList.list
.filter { $0.value.self is AnalyzerRule.Type }
.map(\.key)
Set(analyzerRules).intersection(optInRules)
.sorted()
.forEach {
queuedPrintError("""
warning: '\($0)' should be listed in the 'analyzer_rules' configuration section \
for more clarity as it is only run by 'swiftlint analyze'
""")
}
}
}