-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Warn if a configured rule is not enabled #1806
Warn if a configured rule is not enabled #1806
Conversation
Generated by 🚫 Danger |
Codecov Report
@@ Coverage Diff @@
## master #1806 +/- ##
==========================================
- Coverage 88.79% 88.76% -0.04%
==========================================
Files 229 229
Lines 11284 11315 +31
==========================================
+ Hits 10020 10044 +24
- Misses 1264 1271 +7
Continue to review full report at Codecov.
|
I'm not thrilled about the changes to the public API and the addition of the This also requires manually keeping two states in sync: the At the very least, here are two suggested patches to the current state of this PR: Return early in validateConfiguredRulesAreEnabled
diff --git a/Source/SwiftLintFramework/Extensions/Configuration+Parsing.swift b/Source/SwiftLintFramework/Extensions/Configuration+Parsing.swift
index cf653582..2a48c439 100644
--- a/Source/SwiftLintFramework/Extensions/Configuration+Parsing.swift
+++ b/Source/SwiftLintFramework/Extensions/Configuration+Parsing.swift
@@ -167,6 +167,10 @@ extension Configuration {
internal static func validateConfiguredRulesAreEnabled(rulesMode: Configuration.RulesMode,
configuredRules: [ConfiguredRule]) {
+ if case .allEnabled = rulesMode {
+ return
+ }
+
let rulesWithConfiguration = configuredRules.flatMap {
$0.isDefaultConfiguration ? nil : $0.rule
}
@@ -177,7 +181,7 @@ extension Configuration {
switch rulesMode {
case .allEnabled:
- return
+ fatalError("Unreachable")
case .whitelisted(let whitelist):
if Set(whitelist).isDisjoint(with: identifiers) {
queuedPrintError("\(message), but it is not present on " + and Reuse RuleDescription
to avoid a dynamic runtime type check
diff --git a/Source/SwiftLintFramework/Extensions/Configuration+Parsing.swift b/Source/SwiftLintFramework/Extensions/Configuration+Parsing.swift
index 2a48c439..288a2263 100644
--- a/Source/SwiftLintFramework/Extensions/Configuration+Parsing.swift
+++ b/Source/SwiftLintFramework/Extensions/Configuration+Parsing.swift
@@ -176,8 +176,9 @@ extension Configuration {
}
for rule in rulesWithConfiguration {
- let identifiers = type(of: rule).description.allIdentifiers
- let message = "Found a configuration for '\(type(of: rule).description.identifier)' rule"
+ let ruleDescription = type(of: rule).description
+ let identifiers = ruleDescription.allIdentifiers
+ let message = "Found a configuration for '\(ruleDescription.identifier)' rule"
switch rulesMode {
case .allEnabled: |
The only way I can think of is adding a flag to the |
We'd have to reshuffle quite a few things in order to get it to be automated I think. Looking at OSSCheck, it looks like this might have a slight impact on performance too. Would you mind confirming if that's the case? |
Closes #1350
Pending tests.