Add settings for promoting and demoting fixes#7841
Merged
Conversation
zanieb
commented
Oct 6, 2023
crates/ruff_linter/src/linter.rs
Outdated
| .contains(diagnostic.kind.rule()) | ||
| && fix.applicability().is_always() | ||
| { | ||
| diagnostic.set_fix(fix.clone().with_applicability(Applicability::Sometimes)) |
Member
Author
There was a problem hiding this comment.
Does this clone matter? Is there a better way to do this?
Member
There was a problem hiding this comment.
This would work:
if let Some(fix) = diagnostic.fix.take() {
// Check unsafe before safe so if someone puts a rule in both we are conservative
if settings
.extend_unsafe_fixes
.contains(diagnostic.kind.rule())
&& fix.applicability().is_always()
{
diagnostic.set_fix(fix.with_applicability(Applicability::Sometimes));
} else if settings.extend_safe_fixes.contains(diagnostic.kind.rule())
&& fix.applicability().is_sometimes()
{
diagnostic.set_fix(fix.with_applicability(Applicability::Always));
} else {
diagnostic.set_fix(fix);
}
}There's no Fix::set_applicability(&mut self, ...) (only a mut self method), so usual the if let Some(fix) = &mut diagnostic.fix trick doesn't work here
Member
Author
There was a problem hiding this comment.
Thanks!
Should I have made set_applicability take &mut self?
zanieb
commented
Oct 6, 2023
Comment on lines
+1112
to
+1221
| let ruff_toml = tempdir.path().join("ruff.toml"); | ||
| fs::write( | ||
| &ruff_toml, | ||
| r#" | ||
| [lint] | ||
| extend-unsafe-fixes = ["UP034"] | ||
| "#, | ||
| )?; |
Member
Author
There was a problem hiding this comment.
I copied this testing strategy from the formatter integration tests. Do we have a better place to do this? I'd test more cases (e.g. prefixes, rules in both sets, etc.)
e834178 to
d7140c4
Compare
Contributor
PR Check ResultsEcosystem✅ ecosystem check detected no changes. |
73fc6fb to
f41fd8d
Compare
charliermarsh
approved these changes
Oct 10, 2023
konstin
pushed a commit
that referenced
this pull request
Oct 11, 2023
Adds two configuration-file only settings `extend-safe-fixes` and `extend-unsafe-fixes` which can be used to promote and demote the applicability of fixes for rules. Fixes with `Never` applicability cannot be promoted.
zanieb
added a commit
that referenced
this pull request
Oct 11, 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds two configuration-file only settings
extend-safe-fixesandextend-unsafe-fixeswhich can be used to promote and demote the applicability of fixes for rules.Fixes with
Neverapplicability cannot be promoted.