-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Add settings for promoting and demoting fixes #7841
Conversation
crates/ruff_linter/src/linter.rs
Outdated
.contains(diagnostic.kind.rule()) | ||
&& fix.applicability().is_always() | ||
{ | ||
diagnostic.set_fix(fix.clone().with_applicability(Applicability::Sometimes)) |
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.
Does this clone matter? Is there a better way to do this?
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.
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
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.
Thanks!
Should I have made set_applicability
take &mut self
?
let ruff_toml = tempdir.path().join("ruff.toml"); | ||
fs::write( | ||
&ruff_toml, | ||
r#" | ||
[lint] | ||
extend-unsafe-fixes = ["UP034"] | ||
"#, | ||
)?; |
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 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
PR Check ResultsEcosystem✅ ecosystem check detected no changes. |
73fc6fb
to
f41fd8d
Compare
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.
Adds two configuration-file only settings
extend-safe-fixes
andextend-unsafe-fixes
which can be used to promote and demote the applicability of fixes for rules.Fixes with
Never
applicability cannot be promoted.