-
Notifications
You must be signed in to change notification settings - Fork 2.3k
only rule should work for individual custom rules #6057
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
base: main
Are you sure you want to change the base?
only rule should work for individual custom rules #6057
Conversation
Generated by 🚫 Danger |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR addresses issues #6029 and #6058 by allowing individual custom rules to be enabled via the only_rules configuration (or the --only-rule command line option) without requiring a separate custom_rules configuration. It also adds a convenience property for retrieving CustomRules, sorts custom rule violations deterministically, and updates tests/documentation accordingly.
- Enables specifying individual custom rules in only_rules.
- Introduces lazy evaluation of valid rule identifiers and a new extension for accessing CustomRules.
- Ensures deterministic ordering of custom rule violations.
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
File | Description |
---|---|
Tests/FrameworkTests/CustomRulesTests.swift | Adds tests for only_rules support with custom rules enabling |
Tests/FrameworkTests/ConfigurationTests.swift | Adds test verifying specific custom rules behavior in the configuration |
Source/SwiftLintFramework/Rules/CustomRules.swift | Sorts customRuleConfigurations to guarantee deterministic violation order |
Source/SwiftLintFramework/Configuration/Configuration+RulesWrapper.swift | Refactors rule identifier handling and customRules appending logic |
Source/SwiftLintFramework/Configuration/Configuration+RulesMode.swift | Updates CustomRules handling in rules mode configurations |
Source/SwiftLintFramework/Configuration/Configuration+Parsing.swift | Updates parsing and validation to support custom rule identifiers |
CHANGELOG.md | Documents the bug fix and behavior change for custom_rules configuration |
@@ -11,11 +11,12 @@ internal extension Configuration { | |||
private let aliasResolver: (String) -> String | |||
|
|||
private var invalidRuleIdsWarnedAbout: Set<String> = [] | |||
private var customRulesIdentifiers: Set<String> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had these as lazy
initially, which should be safe, as resultingRules
is locked, and the only other place they are called from is when we're merging configurations, but making them non-lazy seemed safer.
e07e075
to
04d22aa
Compare
04d22aa
to
497fe5f
Compare
Addresses #6029 and #6058
Allows individual custom rules to be specified in the
only_rules
configuration, or the--only-rule
command line option, without also having to specifycustom_rules
.I think this may bring individual custom_rules to be almost equivalent to "normal" rules, as they are now supported in
swiftlint:disable
commands, and most other cases as well.The key change here is that when we calculate the resulting rules, if CustomRules is not in there, we manually add it in.
There was already pre-existing code later on to filter which custom rules are enabled.
Some further changes were required to make sure that the warning about configured but not enabled rules was fired for this configuration in the
only_rules
case.Other changes
We were calling
(allRulesWrapped.first { $0.rule is CustomRules })?.rule as? CustomRules
in about five different places, so I added a conveniencevar
to[ConfigurationRuleWrapper]
.validRuleIdentifiers
is now calculated lazily.Order of custom_rules violations
The order of violations reported by custom_rules was not deterministic - see #6058 - violations are now reported sorted by the custom rule identifier.
There is still some weirdness in the order that violations are output in, but I'll raise those issues elsewhere - they should at least be deterministic now.