mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-19 01:51:30 +00:00
Rename applicability levels to always, sometimes, and never (#7821)
Following much discussion for #4181 at
https://github.com/astral-sh/ruff/pull/5119,
https://github.com/astral-sh/ruff/discussions/5476, #7769,
https://github.com/astral-sh/ruff/pull/7819, and in
[Discord](1159144114
),
this pull request changes `Applicability` from using `Automatic`,
`Suggested`, and `Manual` to `Always`, `Sometimes`, and `Never`.
Also removes `Applicability::Unspecified` (replacing #7792).
This commit is contained in:
parent
7dc9887ab9
commit
b64f403dc2
187 changed files with 386 additions and 381 deletions
|
@ -175,7 +175,7 @@ import os
|
|||
},
|
||||
"filename": "-",
|
||||
"fix": {
|
||||
"applicability": "Automatic",
|
||||
"applicability": "always",
|
||||
"edits": [
|
||||
{
|
||||
"content": "",
|
||||
|
|
|
@ -24,7 +24,7 @@ exit_code: 1
|
|||
},
|
||||
"filename": "/path/to/F401.py",
|
||||
"fix": {
|
||||
"applicability": "Automatic",
|
||||
"applicability": "always",
|
||||
"edits": [
|
||||
{
|
||||
"content": "",
|
||||
|
|
|
@ -5,27 +5,22 @@ use ruff_text_size::{Ranged, TextSize};
|
|||
|
||||
use crate::edit::Edit;
|
||||
|
||||
/// Indicates confidence in the correctness of a suggested fix.
|
||||
#[derive(Default, Copy, Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
|
||||
/// Indicates if a fix can be applied.
|
||||
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
#[cfg_attr(feature = "serde", serde(rename_all = "lowercase"))]
|
||||
pub enum Applicability {
|
||||
/// The fix is definitely what the user intended, or maintains the exact meaning of the code.
|
||||
/// This fix should be automatically applied.
|
||||
Automatic,
|
||||
/// The fix is safe and can always be applied.
|
||||
/// The fix is definitely what the user intended, or it maintains the exact meaning of the code.
|
||||
Always,
|
||||
|
||||
/// The fix may be what the user intended, but it is uncertain.
|
||||
/// The fix should result in valid code if it is applied.
|
||||
/// The fix can be applied with user opt-in.
|
||||
Suggested,
|
||||
/// The fix is unsafe and should only be applied with user opt-in.
|
||||
/// The fix may be what the user intended, but it is uncertain; the resulting code will have valid syntax.
|
||||
Sometimes,
|
||||
|
||||
/// The fix has a good chance of being incorrect or the code be incomplete.
|
||||
/// The fix may result in invalid code if it is applied.
|
||||
/// The fix should only be manually applied by the user.
|
||||
Manual,
|
||||
|
||||
/// The applicability of the fix is unknown.
|
||||
#[default]
|
||||
Unspecified,
|
||||
/// The fix is unsafe and should only be manually applied by the user.
|
||||
/// The fix is likely to be incorrect or the resulting code may have invalid syntax.
|
||||
Never,
|
||||
}
|
||||
|
||||
/// Indicates the level of isolation required to apply a fix.
|
||||
|
@ -52,86 +47,62 @@ pub struct Fix {
|
|||
}
|
||||
|
||||
impl Fix {
|
||||
/// Create a new [`Fix`] with an unspecified applicability from an [`Edit`] element.
|
||||
#[deprecated(
|
||||
note = "Use `Fix::automatic`, `Fix::suggested`, or `Fix::manual` instead to specify an applicability."
|
||||
)]
|
||||
pub fn unspecified(edit: Edit) -> Self {
|
||||
/// Create a new [`Fix`] that can [always](Applicability::Always) be applied from an [`Edit`] element.
|
||||
pub fn always_applies(edit: Edit) -> Self {
|
||||
Self {
|
||||
edits: vec![edit],
|
||||
applicability: Applicability::Unspecified,
|
||||
applicability: Applicability::Always,
|
||||
isolation_level: IsolationLevel::default(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a new [`Fix`] with an unspecified applicability from multiple [`Edit`] elements.
|
||||
#[deprecated(
|
||||
note = "Use `Fix::automatic_edits`, `Fix::suggested_edits`, or `Fix::manual_edits` instead to specify an applicability."
|
||||
)]
|
||||
pub fn unspecified_edits(edit: Edit, rest: impl IntoIterator<Item = Edit>) -> Self {
|
||||
Self {
|
||||
edits: std::iter::once(edit).chain(rest).collect(),
|
||||
applicability: Applicability::Unspecified,
|
||||
isolation_level: IsolationLevel::default(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a new [`Fix`] with [automatic applicability](Applicability::Automatic) from an [`Edit`] element.
|
||||
pub fn automatic(edit: Edit) -> Self {
|
||||
Self {
|
||||
edits: vec![edit],
|
||||
applicability: Applicability::Automatic,
|
||||
isolation_level: IsolationLevel::default(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a new [`Fix`] with [automatic applicability](Applicability::Automatic) from multiple [`Edit`] elements.
|
||||
pub fn automatic_edits(edit: Edit, rest: impl IntoIterator<Item = Edit>) -> Self {
|
||||
/// Create a new [`Fix`] that can [always](Applicability::Always) be applied from multiple [`Edit`] elements.
|
||||
pub fn always_applies_edits(edit: Edit, rest: impl IntoIterator<Item = Edit>) -> Self {
|
||||
let mut edits: Vec<Edit> = std::iter::once(edit).chain(rest).collect();
|
||||
edits.sort_by_key(|edit| (edit.start(), edit.end()));
|
||||
Self {
|
||||
edits,
|
||||
applicability: Applicability::Automatic,
|
||||
applicability: Applicability::Always,
|
||||
isolation_level: IsolationLevel::default(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a new [`Fix`] with [suggested applicability](Applicability::Suggested) from an [`Edit`] element.
|
||||
pub fn suggested(edit: Edit) -> Self {
|
||||
/// Create a new [`Fix`] that can [sometimes](Applicability::Sometimes) be applied from an [`Edit`] element.
|
||||
pub fn sometimes_applies(edit: Edit) -> Self {
|
||||
Self {
|
||||
edits: vec![edit],
|
||||
applicability: Applicability::Suggested,
|
||||
applicability: Applicability::Sometimes,
|
||||
isolation_level: IsolationLevel::default(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a new [`Fix`] with [suggested applicability](Applicability::Suggested) from multiple [`Edit`] elements.
|
||||
pub fn suggested_edits(edit: Edit, rest: impl IntoIterator<Item = Edit>) -> Self {
|
||||
/// Create a new [`Fix`] that can [sometimes](Applicability::Sometimes) be applied from multiple [`Edit`] elements.
|
||||
pub fn sometimes_applies_edits(edit: Edit, rest: impl IntoIterator<Item = Edit>) -> Self {
|
||||
let mut edits: Vec<Edit> = std::iter::once(edit).chain(rest).collect();
|
||||
edits.sort_by_key(|edit| (edit.start(), edit.end()));
|
||||
Self {
|
||||
edits,
|
||||
applicability: Applicability::Suggested,
|
||||
applicability: Applicability::Sometimes,
|
||||
isolation_level: IsolationLevel::default(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a new [`Fix`] with [manual applicability](Applicability::Manual) from an [`Edit`] element.
|
||||
pub fn manual(edit: Edit) -> Self {
|
||||
/// Create a new [`Fix`] that should [never](Applicability::Never) be applied from an [`Edit`] element .
|
||||
pub fn never_applies(edit: Edit) -> Self {
|
||||
Self {
|
||||
edits: vec![edit],
|
||||
applicability: Applicability::Manual,
|
||||
applicability: Applicability::Never,
|
||||
isolation_level: IsolationLevel::default(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a new [`Fix`] with [manual applicability](Applicability::Manual) from multiple [`Edit`] elements.
|
||||
pub fn manual_edits(edit: Edit, rest: impl IntoIterator<Item = Edit>) -> Self {
|
||||
/// Create a new [`Fix`] that should [never](Applicability::Never) be applied from multiple [`Edit`] elements.
|
||||
pub fn never_applies_edits(edit: Edit, rest: impl IntoIterator<Item = Edit>) -> Self {
|
||||
let mut edits: Vec<Edit> = std::iter::once(edit).chain(rest).collect();
|
||||
edits.sort_by_key(|edit| (edit.start(), edit.end()));
|
||||
Self {
|
||||
edits,
|
||||
applicability: Applicability::Manual,
|
||||
applicability: Applicability::Never,
|
||||
isolation_level: IsolationLevel::default(),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ pub(crate) fn bindings(checker: &mut Checker) {
|
|||
binding,
|
||||
checker.locator,
|
||||
)
|
||||
.map(Fix::automatic)
|
||||
.map(Fix::always_applies)
|
||||
});
|
||||
}
|
||||
checker.diagnostics.push(diagnostic);
|
||||
|
|
|
@ -110,8 +110,10 @@ pub(crate) fn check_noqa(
|
|||
let mut diagnostic =
|
||||
Diagnostic::new(UnusedNOQA { codes: None }, directive.range());
|
||||
if settings.rules.should_fix(diagnostic.kind.rule()) {
|
||||
diagnostic
|
||||
.set_fix(Fix::suggested(delete_noqa(directive.range(), locator)));
|
||||
diagnostic.set_fix(Fix::sometimes_applies(delete_noqa(
|
||||
directive.range(),
|
||||
locator,
|
||||
)));
|
||||
}
|
||||
diagnostics.push(diagnostic);
|
||||
}
|
||||
|
@ -175,15 +177,17 @@ pub(crate) fn check_noqa(
|
|||
);
|
||||
if settings.rules.should_fix(diagnostic.kind.rule()) {
|
||||
if valid_codes.is_empty() {
|
||||
diagnostic.set_fix(Fix::suggested(delete_noqa(
|
||||
diagnostic.set_fix(Fix::sometimes_applies(delete_noqa(
|
||||
directive.range(),
|
||||
locator,
|
||||
)));
|
||||
} else {
|
||||
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::sometimes_applies(
|
||||
Edit::range_replacement(
|
||||
format!("# noqa: {}", valid_codes.join(", ")),
|
||||
directive.range(),
|
||||
)));
|
||||
),
|
||||
));
|
||||
}
|
||||
}
|
||||
diagnostics.push(diagnostic);
|
||||
|
|
|
@ -151,7 +151,7 @@ mod tests {
|
|||
// The choice of rule here is arbitrary.
|
||||
kind: MissingNewlineAtEndOfFile.into(),
|
||||
range: edit.range(),
|
||||
fix: Some(Fix::unspecified(edit)),
|
||||
fix: Some(Fix::always_applies(edit)),
|
||||
parent: None,
|
||||
})
|
||||
.collect()
|
||||
|
|
|
@ -52,10 +52,10 @@ impl Display for Diff<'_> {
|
|||
let diff = TextDiff::from_lines(self.source_code.source_text(), &output);
|
||||
|
||||
let message = match self.fix.applicability() {
|
||||
Applicability::Automatic => "Fix",
|
||||
Applicability::Suggested => "Suggested fix",
|
||||
Applicability::Manual => "Possible fix",
|
||||
Applicability::Unspecified => "Suggested fix", /* For backwards compatibility, unspecified fixes are 'suggested' */
|
||||
// TODO(zanieb): Adjust this messaging once it's user-facing
|
||||
Applicability::Always => "Fix",
|
||||
Applicability::Sometimes => "Suggested fix",
|
||||
Applicability::Never => "Possible fix",
|
||||
};
|
||||
writeln!(f, "ℹ {}", message.blue())?;
|
||||
|
||||
|
|
|
@ -178,10 +178,9 @@ def fibonacci(n):
|
|||
},
|
||||
TextRange::new(TextSize::from(7), TextSize::from(9)),
|
||||
)
|
||||
.with_fix(Fix::suggested(Edit::range_deletion(TextRange::new(
|
||||
TextSize::from(0),
|
||||
TextSize::from(10),
|
||||
))));
|
||||
.with_fix(Fix::sometimes_applies(Edit::range_deletion(
|
||||
TextRange::new(TextSize::from(0), TextSize::from(10)),
|
||||
)));
|
||||
|
||||
let fib_source = SourceFileBuilder::new("fib.py", fib).finish();
|
||||
|
||||
|
@ -193,7 +192,7 @@ def fibonacci(n):
|
|||
},
|
||||
TextRange::new(TextSize::from(94), TextSize::from(95)),
|
||||
)
|
||||
.with_fix(Fix::suggested(Edit::deletion(
|
||||
.with_fix(Fix::sometimes_applies(Edit::deletion(
|
||||
TextSize::from(94),
|
||||
TextSize::from(99),
|
||||
)));
|
||||
|
|
|
@ -11,7 +11,7 @@ expression: content
|
|||
},
|
||||
"filename": "fib.py",
|
||||
"fix": {
|
||||
"applicability": "Suggested",
|
||||
"applicability": "sometimes",
|
||||
"edits": [
|
||||
{
|
||||
"content": "",
|
||||
|
@ -43,7 +43,7 @@ expression: content
|
|||
},
|
||||
"filename": "fib.py",
|
||||
"fix": {
|
||||
"applicability": "Suggested",
|
||||
"applicability": "sometimes",
|
||||
"edits": [
|
||||
{
|
||||
"content": "",
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
source: crates/ruff_linter/src/message/json_lines.rs
|
||||
expression: content
|
||||
---
|
||||
{"code":"F401","end_location":{"column":10,"row":1},"filename":"fib.py","fix":{"applicability":"Suggested","edits":[{"content":"","end_location":{"column":1,"row":2},"location":{"column":1,"row":1}}],"message":"Remove unused import: `os`"},"location":{"column":8,"row":1},"message":"`os` imported but unused","noqa_row":1,"url":"https://docs.astral.sh/ruff/rules/unused-import"}
|
||||
{"code":"F841","end_location":{"column":6,"row":6},"filename":"fib.py","fix":{"applicability":"Suggested","edits":[{"content":"","end_location":{"column":10,"row":6},"location":{"column":5,"row":6}}],"message":"Remove assignment to unused variable `x`"},"location":{"column":5,"row":6},"message":"Local variable `x` is assigned to but never used","noqa_row":6,"url":"https://docs.astral.sh/ruff/rules/unused-variable"}
|
||||
{"code":"F401","end_location":{"column":10,"row":1},"filename":"fib.py","fix":{"applicability":"sometimes","edits":[{"content":"","end_location":{"column":1,"row":2},"location":{"column":1,"row":1}}],"message":"Remove unused import: `os`"},"location":{"column":8,"row":1},"message":"`os` imported but unused","noqa_row":1,"url":"https://docs.astral.sh/ruff/rules/unused-import"}
|
||||
{"code":"F841","end_location":{"column":6,"row":6},"filename":"fib.py","fix":{"applicability":"sometimes","edits":[{"content":"","end_location":{"column":10,"row":6},"location":{"column":5,"row":6}}],"message":"Remove assignment to unused variable `x`"},"location":{"column":5,"row":6},"message":"Local variable `x` is assigned to but never used","noqa_row":6,"url":"https://docs.astral.sh/ruff/rules/unused-variable"}
|
||||
{"code":"F821","end_location":{"column":5,"row":1},"filename":"undef.py","fix":null,"location":{"column":4,"row":1},"message":"Undefined name `a`","noqa_row":1,"url":"https://docs.astral.sh/ruff/rules/undefined-name"}
|
||||
|
||||
|
|
|
@ -68,7 +68,7 @@ pub(crate) fn commented_out_code(
|
|||
let mut diagnostic = Diagnostic::new(CommentedOutCode, *range);
|
||||
|
||||
if settings.rules.should_fix(Rule::CommentedOutCode) {
|
||||
diagnostic.set_fix(Fix::manual(Edit::range_deletion(
|
||||
diagnostic.set_fix(Fix::never_applies(Edit::range_deletion(
|
||||
locator.full_lines_range(*range),
|
||||
)));
|
||||
}
|
||||
|
|
|
@ -703,7 +703,7 @@ pub(crate) fn definition(
|
|||
function.identifier(),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.set_fix(Fix::suggested(Edit::insertion(
|
||||
diagnostic.set_fix(Fix::sometimes_applies(Edit::insertion(
|
||||
" -> None".to_string(),
|
||||
function.parameters.range().end(),
|
||||
)));
|
||||
|
@ -721,7 +721,7 @@ pub(crate) fn definition(
|
|||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
if let Some(return_type) = simple_magic_return_type(name) {
|
||||
diagnostic.set_fix(Fix::suggested(Edit::insertion(
|
||||
diagnostic.set_fix(Fix::sometimes_applies(Edit::insertion(
|
||||
format!(" -> {return_type}"),
|
||||
function.parameters.range().end(),
|
||||
)));
|
||||
|
|
|
@ -76,7 +76,7 @@ pub(crate) fn assert_false(checker: &mut Checker, stmt: &Stmt, test: &Expr, msg:
|
|||
|
||||
let mut diagnostic = Diagnostic::new(AssertFalse, test.range());
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::sometimes_applies(Edit::range_replacement(
|
||||
checker.generator().stmt(&assertion_error(msg)),
|
||||
stmt.range(),
|
||||
)));
|
||||
|
|
|
@ -147,7 +147,7 @@ fn duplicate_handler_exceptions<'a>(
|
|||
expr.range(),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.set_fix(Fix::automatic(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::always_applies(Edit::range_replacement(
|
||||
// Single exceptions don't require parentheses, but since we're _removing_
|
||||
// parentheses, insert whitespace as needed.
|
||||
if let [elt] = unique_elts.as_slice() {
|
||||
|
|
|
@ -86,7 +86,7 @@ pub(crate) fn getattr_with_constant(
|
|||
|
||||
let mut diagnostic = Diagnostic::new(GetAttrWithConstant, expr.range());
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::sometimes_applies(Edit::range_replacement(
|
||||
pad(
|
||||
if matches!(
|
||||
obj,
|
||||
|
|
|
@ -200,5 +200,8 @@ fn move_initialization(
|
|||
}
|
||||
|
||||
let initialization_edit = Edit::insertion(content, pos);
|
||||
Some(Fix::manual_edits(default_edit, [initialization_edit]))
|
||||
Some(Fix::never_applies_edits(
|
||||
default_edit,
|
||||
[initialization_edit],
|
||||
))
|
||||
}
|
||||
|
|
|
@ -85,7 +85,7 @@ pub(crate) fn redundant_tuple_in_exception_handler(
|
|||
// ```
|
||||
// Otherwise, the output will be invalid syntax, since we're removing a set of
|
||||
// parentheses.
|
||||
diagnostic.set_fix(Fix::automatic(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::always_applies(Edit::range_replacement(
|
||||
pad(
|
||||
checker.generator().expr(elt),
|
||||
type_.range(),
|
||||
|
|
|
@ -109,7 +109,7 @@ pub(crate) fn setattr_with_constant(
|
|||
if expr == child.as_ref() {
|
||||
let mut diagnostic = Diagnostic::new(SetAttrWithConstant, expr.range());
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::sometimes_applies(Edit::range_replacement(
|
||||
assignment(obj, name, value, checker.generator()),
|
||||
expr.range(),
|
||||
)));
|
||||
|
|
|
@ -83,7 +83,7 @@ pub(crate) fn unreliable_callable_check(
|
|||
if checker.patch(diagnostic.kind.rule()) {
|
||||
if id == "hasattr" {
|
||||
if checker.semantic().is_builtin("callable") {
|
||||
diagnostic.set_fix(Fix::automatic(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::always_applies(Edit::range_replacement(
|
||||
format!("callable({})", checker.locator().slice(obj)),
|
||||
expr.range(),
|
||||
)));
|
||||
|
|
|
@ -168,7 +168,7 @@ pub(crate) fn unused_loop_control_variable(checker: &mut Checker, stmt_for: &ast
|
|||
.filter(|binding| binding.start() >= expr.start())
|
||||
.all(|binding| !binding.is_used())
|
||||
{
|
||||
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::sometimes_applies(Edit::range_replacement(
|
||||
rename,
|
||||
expr.range(),
|
||||
)));
|
||||
|
|
|
@ -325,7 +325,9 @@ pub(crate) fn trailing_commas(
|
|||
let comma = prev.spanned.unwrap();
|
||||
let mut diagnostic = Diagnostic::new(ProhibitedTrailingComma, comma.1);
|
||||
if settings.rules.should_fix(Rule::ProhibitedTrailingComma) {
|
||||
diagnostic.set_fix(Fix::automatic(Edit::range_deletion(diagnostic.range())));
|
||||
diagnostic.set_fix(Fix::always_applies(Edit::range_deletion(
|
||||
diagnostic.range(),
|
||||
)));
|
||||
}
|
||||
diagnostics.push(diagnostic);
|
||||
}
|
||||
|
@ -365,7 +367,7 @@ pub(crate) fn trailing_commas(
|
|||
// removing any brackets in the same linter pass - doing both at the same time could
|
||||
// lead to a syntax error.
|
||||
let contents = locator.slice(missing_comma.1);
|
||||
diagnostic.set_fix(Fix::automatic(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::always_applies(Edit::range_replacement(
|
||||
format!("{contents},"),
|
||||
missing_comma.1,
|
||||
)));
|
||||
|
|
|
@ -1293,7 +1293,7 @@ pub(crate) fn fix_unnecessary_comprehension_any_all(
|
|||
_ => whitespace_after_arg,
|
||||
};
|
||||
|
||||
Ok(Fix::suggested(Edit::range_replacement(
|
||||
Ok(Fix::sometimes_applies(Edit::range_replacement(
|
||||
tree.codegen_stylist(stylist),
|
||||
expr.range(),
|
||||
)))
|
||||
|
|
|
@ -90,9 +90,9 @@ pub(crate) fn unnecessary_call_around_sorted(
|
|||
checker.stylist(),
|
||||
)?;
|
||||
if outer.id == "reversed" {
|
||||
Ok(Fix::suggested(edit))
|
||||
Ok(Fix::sometimes_applies(edit))
|
||||
} else {
|
||||
Ok(Fix::automatic(edit))
|
||||
Ok(Fix::always_applies(edit))
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -88,7 +88,7 @@ pub(crate) fn unnecessary_collection_call(
|
|||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.try_set_fix(|| {
|
||||
fixes::fix_unnecessary_collection_call(expr, checker).map(Fix::suggested)
|
||||
fixes::fix_unnecessary_collection_call(expr, checker).map(Fix::sometimes_applies)
|
||||
});
|
||||
}
|
||||
checker.diagnostics.push(diagnostic);
|
||||
|
|
|
@ -67,7 +67,7 @@ fn add_diagnostic(checker: &mut Checker, expr: &Expr) {
|
|||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.try_set_fix(|| {
|
||||
fixes::fix_unnecessary_comprehension(expr, checker.locator(), checker.stylist())
|
||||
.map(Fix::suggested)
|
||||
.map(Fix::sometimes_applies)
|
||||
});
|
||||
}
|
||||
checker.diagnostics.push(diagnostic);
|
||||
|
|
|
@ -137,7 +137,7 @@ pub(crate) fn unnecessary_double_cast_or_process(
|
|||
checker.locator(),
|
||||
checker.stylist(),
|
||||
)
|
||||
.map(Fix::suggested)
|
||||
.map(Fix::sometimes_applies)
|
||||
});
|
||||
}
|
||||
checker.diagnostics.push(diagnostic);
|
||||
|
|
|
@ -69,7 +69,7 @@ pub(crate) fn unnecessary_generator_dict(
|
|||
let mut diagnostic = Diagnostic::new(UnnecessaryGeneratorDict, expr.range());
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.try_set_fix(|| {
|
||||
fixes::fix_unnecessary_generator_dict(expr, checker).map(Fix::suggested)
|
||||
fixes::fix_unnecessary_generator_dict(expr, checker).map(Fix::sometimes_applies)
|
||||
});
|
||||
}
|
||||
checker.diagnostics.push(diagnostic);
|
||||
|
|
|
@ -63,7 +63,7 @@ pub(crate) fn unnecessary_generator_list(
|
|||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.try_set_fix(|| {
|
||||
fixes::fix_unnecessary_generator_list(expr, checker.locator(), checker.stylist())
|
||||
.map(Fix::suggested)
|
||||
.map(Fix::sometimes_applies)
|
||||
});
|
||||
}
|
||||
checker.diagnostics.push(diagnostic);
|
||||
|
|
|
@ -62,7 +62,7 @@ pub(crate) fn unnecessary_generator_set(
|
|||
let mut diagnostic = Diagnostic::new(UnnecessaryGeneratorSet, expr.range());
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.try_set_fix(|| {
|
||||
fixes::fix_unnecessary_generator_set(expr, checker).map(Fix::suggested)
|
||||
fixes::fix_unnecessary_generator_set(expr, checker).map(Fix::sometimes_applies)
|
||||
});
|
||||
}
|
||||
checker.diagnostics.push(diagnostic);
|
||||
|
|
|
@ -59,7 +59,7 @@ pub(crate) fn unnecessary_list_call(
|
|||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.try_set_fix(|| {
|
||||
fixes::fix_unnecessary_list_call(expr, checker.locator(), checker.stylist())
|
||||
.map(Fix::suggested)
|
||||
.map(Fix::sometimes_applies)
|
||||
});
|
||||
}
|
||||
checker.diagnostics.push(diagnostic);
|
||||
|
|
|
@ -67,7 +67,8 @@ pub(crate) fn unnecessary_list_comprehension_dict(
|
|||
let mut diagnostic = Diagnostic::new(UnnecessaryListComprehensionDict, expr.range());
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.try_set_fix(|| {
|
||||
fixes::fix_unnecessary_list_comprehension_dict(expr, checker).map(Fix::suggested)
|
||||
fixes::fix_unnecessary_list_comprehension_dict(expr, checker)
|
||||
.map(Fix::sometimes_applies)
|
||||
});
|
||||
}
|
||||
checker.diagnostics.push(diagnostic);
|
||||
|
|
|
@ -60,7 +60,8 @@ pub(crate) fn unnecessary_list_comprehension_set(
|
|||
let mut diagnostic = Diagnostic::new(UnnecessaryListComprehensionSet, expr.range());
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.try_set_fix(|| {
|
||||
fixes::fix_unnecessary_list_comprehension_set(expr, checker).map(Fix::suggested)
|
||||
fixes::fix_unnecessary_list_comprehension_set(expr, checker)
|
||||
.map(Fix::sometimes_applies)
|
||||
});
|
||||
}
|
||||
checker.diagnostics.push(diagnostic);
|
||||
|
|
|
@ -81,8 +81,9 @@ pub(crate) fn unnecessary_literal_dict(
|
|||
expr.range(),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic
|
||||
.try_set_fix(|| fixes::fix_unnecessary_literal_dict(expr, checker).map(Fix::suggested));
|
||||
diagnostic.try_set_fix(|| {
|
||||
fixes::fix_unnecessary_literal_dict(expr, checker).map(Fix::sometimes_applies)
|
||||
});
|
||||
}
|
||||
checker.diagnostics.push(diagnostic);
|
||||
}
|
||||
|
|
|
@ -76,8 +76,9 @@ pub(crate) fn unnecessary_literal_set(
|
|||
expr.range(),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic
|
||||
.try_set_fix(|| fixes::fix_unnecessary_literal_set(expr, checker).map(Fix::suggested));
|
||||
diagnostic.try_set_fix(|| {
|
||||
fixes::fix_unnecessary_literal_set(expr, checker).map(Fix::sometimes_applies)
|
||||
});
|
||||
}
|
||||
checker.diagnostics.push(diagnostic);
|
||||
}
|
||||
|
|
|
@ -98,7 +98,7 @@ pub(crate) fn unnecessary_literal_within_dict_call(
|
|||
checker.locator(),
|
||||
checker.stylist(),
|
||||
)
|
||||
.map(Fix::suggested)
|
||||
.map(Fix::sometimes_applies)
|
||||
});
|
||||
}
|
||||
checker.diagnostics.push(diagnostic);
|
||||
|
|
|
@ -100,7 +100,7 @@ pub(crate) fn unnecessary_literal_within_list_call(
|
|||
checker.locator(),
|
||||
checker.stylist(),
|
||||
)
|
||||
.map(Fix::suggested)
|
||||
.map(Fix::sometimes_applies)
|
||||
});
|
||||
}
|
||||
checker.diagnostics.push(diagnostic);
|
||||
|
|
|
@ -102,7 +102,7 @@ pub(crate) fn unnecessary_literal_within_tuple_call(
|
|||
checker.locator(),
|
||||
checker.stylist(),
|
||||
)
|
||||
.map(Fix::suggested)
|
||||
.map(Fix::sometimes_applies)
|
||||
});
|
||||
}
|
||||
checker.diagnostics.push(diagnostic);
|
||||
|
|
|
@ -230,7 +230,7 @@ pub(crate) fn unnecessary_map(
|
|||
checker.locator(),
|
||||
checker.stylist(),
|
||||
)
|
||||
.map(Fix::suggested)
|
||||
.map(Fix::sometimes_applies)
|
||||
});
|
||||
}
|
||||
checker.diagnostics.push(diagnostic);
|
||||
|
|
|
@ -293,7 +293,7 @@ fn generate_fix(
|
|||
range: TextRange::default(),
|
||||
});
|
||||
|
||||
Fix::suggested_edits(
|
||||
Fix::sometimes_applies_edits(
|
||||
Edit::insertion(
|
||||
format!(
|
||||
"{}{}{}",
|
||||
|
|
|
@ -69,7 +69,7 @@ pub(crate) fn shebang_leading_whitespace(
|
|||
let prefix = TextRange::up_to(range.start());
|
||||
let mut diagnostic = Diagnostic::new(ShebangLeadingWhitespace, prefix);
|
||||
if settings.rules.should_fix(diagnostic.kind.rule()) {
|
||||
diagnostic.set_fix(Fix::automatic(Edit::range_deletion(prefix)));
|
||||
diagnostic.set_fix(Fix::always_applies(Edit::range_deletion(prefix)));
|
||||
}
|
||||
Some(diagnostic)
|
||||
}
|
||||
|
|
|
@ -169,7 +169,7 @@ fn concatenate_strings(a_range: TextRange, b_range: TextRange, locator: &Locator
|
|||
let concatenation = format!("{a_leading_quote}{a_body}{b_body}{a_trailing_quote}");
|
||||
let range = TextRange::new(a_range.start(), b_range.end());
|
||||
|
||||
Some(Fix::automatic(Edit::range_replacement(
|
||||
Some(Fix::always_applies(Edit::range_replacement(
|
||||
concatenation,
|
||||
range,
|
||||
)))
|
||||
|
|
|
@ -86,7 +86,7 @@ pub(crate) fn unconventional_import_alias(
|
|||
let scope = &checker.semantic().scopes[binding.scope];
|
||||
let (edit, rest) =
|
||||
Renamer::rename(name, expected_alias, scope, checker.semantic())?;
|
||||
Ok(Fix::suggested_edits(edit, rest))
|
||||
Ok(Fix::sometimes_applies_edits(edit, rest))
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -69,7 +69,7 @@ pub(crate) fn direct_logger_instantiation(checker: &mut Checker, call: &ast::Exp
|
|||
checker.semantic(),
|
||||
)?;
|
||||
let reference_edit = Edit::range_replacement(binding, call.func.range());
|
||||
Ok(Fix::suggested_edits(import_edit, [reference_edit]))
|
||||
Ok(Fix::sometimes_applies_edits(import_edit, [reference_edit]))
|
||||
});
|
||||
}
|
||||
checker.diagnostics.push(diagnostic);
|
||||
|
|
|
@ -82,7 +82,7 @@ pub(crate) fn invalid_get_logger_argument(checker: &mut Checker, call: &ast::Exp
|
|||
let mut diagnostic = Diagnostic::new(InvalidGetLoggerArgument, expr.range());
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
if checker.semantic().is_builtin("__name__") {
|
||||
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::sometimes_applies(Edit::range_replacement(
|
||||
"__name__".to_string(),
|
||||
expr.range(),
|
||||
)));
|
||||
|
|
|
@ -63,7 +63,7 @@ pub(crate) fn undocumented_warn(checker: &mut Checker, expr: &Expr) {
|
|||
checker.semantic(),
|
||||
)?;
|
||||
let reference_edit = Edit::range_replacement(binding, expr.range());
|
||||
Ok(Fix::suggested_edits(import_edit, [reference_edit]))
|
||||
Ok(Fix::sometimes_applies_edits(import_edit, [reference_edit]))
|
||||
});
|
||||
}
|
||||
checker.diagnostics.push(diagnostic);
|
||||
|
|
|
@ -197,7 +197,7 @@ pub(crate) fn logging_call(checker: &mut Checker, call: &ast::ExprCall) {
|
|||
) {
|
||||
let mut diagnostic = Diagnostic::new(LoggingWarn, range);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.set_fix(Fix::automatic(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::always_applies(Edit::range_replacement(
|
||||
"warning".to_string(),
|
||||
range,
|
||||
)));
|
||||
|
|
|
@ -82,7 +82,7 @@ pub(crate) fn duplicate_class_field_definition(checker: &mut Checker, body: &[St
|
|||
if checker.patch(diagnostic.kind.rule()) {
|
||||
let edit =
|
||||
fix::edits::delete_stmt(stmt, Some(stmt), checker.locator(), checker.indexer());
|
||||
diagnostic.set_fix(Fix::suggested(edit).isolate(Checker::isolation(
|
||||
diagnostic.set_fix(Fix::sometimes_applies(edit).isolate(Checker::isolation(
|
||||
checker.semantic().current_statement_id(),
|
||||
)));
|
||||
}
|
||||
|
|
|
@ -196,7 +196,7 @@ pub(crate) fn multiple_starts_ends_with(checker: &mut Checker, expr: &Expr) {
|
|||
range: TextRange::default(),
|
||||
});
|
||||
let bool_op = node;
|
||||
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::sometimes_applies(Edit::range_replacement(
|
||||
checker.generator().expr(&bool_op),
|
||||
expr.range(),
|
||||
)));
|
||||
|
|
|
@ -66,7 +66,7 @@ pub(crate) fn reimplemented_list_builtin(checker: &mut Checker, expr: &ExprLambd
|
|||
let mut diagnostic = Diagnostic::new(ReimplementedListBuiltin, expr.range());
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
if checker.semantic().is_builtin("list") {
|
||||
diagnostic.set_fix(Fix::automatic(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::always_applies(Edit::range_replacement(
|
||||
"list".to_string(),
|
||||
expr.range(),
|
||||
)));
|
||||
|
|
|
@ -70,7 +70,7 @@ pub(crate) fn no_unnecessary_pass(checker: &mut Checker, body: &[Stmt]) {
|
|||
} else {
|
||||
fix::edits::delete_stmt(stmt, None, checker.locator(), checker.indexer())
|
||||
};
|
||||
diagnostic.set_fix(Fix::automatic(edit).isolate(Checker::isolation(
|
||||
diagnostic.set_fix(Fix::always_applies(edit).isolate(Checker::isolation(
|
||||
checker.semantic().current_statement_id(),
|
||||
)));
|
||||
}
|
||||
|
|
|
@ -86,7 +86,7 @@ pub(crate) fn unnecessary_range_start(checker: &mut Checker, call: &ast::ExprCal
|
|||
Parentheses::Preserve,
|
||||
checker.locator().contents(),
|
||||
)
|
||||
.map(Fix::automatic)
|
||||
.map(Fix::always_applies)
|
||||
});
|
||||
}
|
||||
checker.diagnostics.push(diagnostic);
|
||||
|
|
|
@ -81,7 +81,7 @@ pub(crate) fn any_eq_ne_annotation(checker: &mut Checker, name: &str, parameters
|
|||
if checker.patch(diagnostic.kind.rule()) {
|
||||
// Ex) `def __eq__(self, obj: Any): ...`
|
||||
if checker.semantic().is_builtin("object") {
|
||||
diagnostic.set_fix(Fix::automatic(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::always_applies(Edit::range_replacement(
|
||||
"object".to_string(),
|
||||
annotation.range(),
|
||||
)));
|
||||
|
|
|
@ -72,7 +72,7 @@ pub(crate) fn duplicate_union_member<'a>(checker: &mut Checker, expr: &'a Expr)
|
|||
if let Some(parent @ Expr::BinOp(ast::ExprBinOp { left, right, .. })) = parent {
|
||||
// Replace the parent with its non-duplicate child.
|
||||
let child = if expr == left.as_ref() { right } else { left };
|
||||
diagnostic.set_fix(Fix::automatic(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::always_applies(Edit::range_replacement(
|
||||
checker.locator().slice(child.as_ref()).to_string(),
|
||||
parent.range(),
|
||||
)));
|
||||
|
|
|
@ -66,7 +66,7 @@ pub(crate) fn ellipsis_in_non_empty_class_body(checker: &mut Checker, body: &[St
|
|||
if checker.patch(diagnostic.kind.rule()) {
|
||||
let edit =
|
||||
fix::edits::delete_stmt(stmt, Some(stmt), checker.locator(), checker.indexer());
|
||||
diagnostic.set_fix(Fix::automatic(edit).isolate(Checker::isolation(
|
||||
diagnostic.set_fix(Fix::always_applies(edit).isolate(Checker::isolation(
|
||||
checker.semantic().current_statement_id(),
|
||||
)));
|
||||
}
|
||||
|
|
|
@ -177,7 +177,7 @@ fn check_short_args_list(checker: &mut Checker, parameters: &Parameters, func_ki
|
|||
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
if checker.semantic().is_builtin("object") {
|
||||
diagnostic.set_fix(Fix::automatic(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::always_applies(Edit::range_replacement(
|
||||
"object".to_string(),
|
||||
annotation.range(),
|
||||
)));
|
||||
|
|
|
@ -70,7 +70,7 @@ pub(crate) fn non_empty_stub_body(checker: &mut Checker, body: &[Stmt]) {
|
|||
|
||||
let mut diagnostic = Diagnostic::new(NonEmptyStubBody, stmt.range());
|
||||
if checker.patch(Rule::NonEmptyStubBody) {
|
||||
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::sometimes_applies(Edit::range_replacement(
|
||||
format!("..."),
|
||||
stmt.range(),
|
||||
)));
|
||||
|
|
|
@ -51,7 +51,7 @@ pub(crate) fn numeric_literal_too_long(checker: &mut Checker, expr: &Expr) {
|
|||
|
||||
let mut diagnostic = Diagnostic::new(NumericLiteralTooLong, expr.range());
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::sometimes_applies(Edit::range_replacement(
|
||||
"...".to_string(),
|
||||
expr.range(),
|
||||
)));
|
||||
|
|
|
@ -63,7 +63,7 @@ pub(crate) fn pass_in_class_body(checker: &mut Checker, class_def: &ast::StmtCla
|
|||
if checker.patch(diagnostic.kind.rule()) {
|
||||
let edit =
|
||||
fix::edits::delete_stmt(stmt, Some(stmt), checker.locator(), checker.indexer());
|
||||
diagnostic.set_fix(Fix::automatic(edit).isolate(Checker::isolation(
|
||||
diagnostic.set_fix(Fix::always_applies(edit).isolate(Checker::isolation(
|
||||
checker.semantic().current_statement_id(),
|
||||
)));
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ pub(crate) fn pass_statement_stub_body(checker: &mut Checker, body: &[Stmt]) {
|
|||
|
||||
let mut diagnostic = Diagnostic::new(PassStatementStubBody, pass.range());
|
||||
if checker.patch(Rule::PassStatementStubBody) {
|
||||
diagnostic.set_fix(Fix::automatic(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::always_applies(Edit::range_replacement(
|
||||
format!("..."),
|
||||
pass.range(),
|
||||
)));
|
||||
|
|
|
@ -44,7 +44,7 @@ impl AlwaysFixableViolation for QuotedAnnotationInStub {
|
|||
pub(crate) fn quoted_annotation_in_stub(checker: &mut Checker, annotation: &str, range: TextRange) {
|
||||
let mut diagnostic = Diagnostic::new(QuotedAnnotationInStub, range);
|
||||
if checker.patch(Rule::QuotedAnnotationInStub) {
|
||||
diagnostic.set_fix(Fix::automatic(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::always_applies(Edit::range_replacement(
|
||||
annotation.to_string(),
|
||||
range,
|
||||
)));
|
||||
|
|
|
@ -535,7 +535,7 @@ pub(crate) fn typed_argument_simple_defaults(checker: &mut Checker, parameters:
|
|||
let mut diagnostic = Diagnostic::new(TypedArgumentDefaultInStub, default.range());
|
||||
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::sometimes_applies(Edit::range_replacement(
|
||||
"...".to_string(),
|
||||
default.range(),
|
||||
)));
|
||||
|
@ -572,7 +572,7 @@ pub(crate) fn argument_simple_defaults(checker: &mut Checker, parameters: &Param
|
|||
let mut diagnostic = Diagnostic::new(ArgumentDefaultInStub, default.range());
|
||||
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::sometimes_applies(Edit::range_replacement(
|
||||
"...".to_string(),
|
||||
default.range(),
|
||||
)));
|
||||
|
@ -607,7 +607,7 @@ pub(crate) fn assignment_default_in_stub(checker: &mut Checker, targets: &[Expr]
|
|||
|
||||
let mut diagnostic = Diagnostic::new(AssignmentDefaultInStub, value.range());
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::sometimes_applies(Edit::range_replacement(
|
||||
"...".to_string(),
|
||||
value.range(),
|
||||
)));
|
||||
|
@ -643,7 +643,7 @@ pub(crate) fn annotated_assignment_default_in_stub(
|
|||
|
||||
let mut diagnostic = Diagnostic::new(AssignmentDefaultInStub, value.range());
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::sometimes_applies(Edit::range_replacement(
|
||||
"...".to_string(),
|
||||
value.range(),
|
||||
)));
|
||||
|
@ -748,7 +748,7 @@ pub(crate) fn type_alias_without_annotation(checker: &mut Checker, value: &Expr,
|
|||
target.start(),
|
||||
checker.semantic(),
|
||||
)?;
|
||||
Ok(Fix::suggested_edits(
|
||||
Ok(Fix::sometimes_applies_edits(
|
||||
Edit::range_replacement(format!("{id}: {binding}"), target.range()),
|
||||
[import_edit],
|
||||
))
|
||||
|
|
|
@ -99,7 +99,7 @@ pub(crate) fn str_or_repr_defined_in_stub(checker: &mut Checker, stmt: &Stmt) {
|
|||
let stmt = checker.semantic().current_statement();
|
||||
let parent = checker.semantic().current_statement_parent();
|
||||
let edit = delete_stmt(stmt, parent, checker.locator(), checker.indexer());
|
||||
diagnostic.set_fix(Fix::automatic(edit).isolate(Checker::isolation(
|
||||
diagnostic.set_fix(Fix::always_applies(edit).isolate(Checker::isolation(
|
||||
checker.semantic().current_statement_parent_id(),
|
||||
)));
|
||||
}
|
||||
|
|
|
@ -68,7 +68,7 @@ pub(crate) fn string_or_bytes_too_long(checker: &mut Checker, expr: &Expr) {
|
|||
|
||||
let mut diagnostic = Diagnostic::new(StringOrBytesTooLong, expr.range());
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::sometimes_applies(Edit::range_replacement(
|
||||
"...".to_string(),
|
||||
expr.range(),
|
||||
)));
|
||||
|
|
|
@ -70,7 +70,7 @@ pub(crate) fn unaliased_collections_abc_set_import(
|
|||
diagnostic.try_set_fix(|| {
|
||||
let scope = &checker.semantic().scopes[binding.scope];
|
||||
let (edit, rest) = Renamer::rename(name, "AbstractSet", scope, checker.semantic())?;
|
||||
Ok(Fix::suggested_edits(edit, rest))
|
||||
Ok(Fix::sometimes_applies_edits(edit, rest))
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -292,7 +292,7 @@ pub(crate) fn unittest_assertion(
|
|||
&& !checker.indexer().comment_ranges().intersects(expr.range())
|
||||
{
|
||||
if let Ok(stmt) = unittest_assert.generate_assert(args, keywords) {
|
||||
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::sometimes_applies(Edit::range_replacement(
|
||||
checker.generator().stmt(&stmt),
|
||||
parenthesized_range(
|
||||
expr.into(),
|
||||
|
@ -401,7 +401,7 @@ pub(crate) fn unittest_raises_assertion(
|
|||
checker.semantic(),
|
||||
)?;
|
||||
let edit = Edit::range_replacement(format!("{binding}({args})"), call.range());
|
||||
Ok(Fix::suggested_edits(import_edit, [edit]))
|
||||
Ok(Fix::sometimes_applies_edits(import_edit, [edit]))
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -756,7 +756,7 @@ pub(crate) fn composite_condition(
|
|||
{
|
||||
diagnostic.try_set_fix(|| {
|
||||
fix_composite_condition(stmt, checker.locator(), checker.stylist())
|
||||
.map(Fix::suggested)
|
||||
.map(Fix::sometimes_applies)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -700,7 +700,7 @@ fn check_fixture_decorator(checker: &mut Checker, func_name: &str, decorator: &D
|
|||
&& arguments.args.is_empty()
|
||||
&& arguments.keywords.is_empty()
|
||||
{
|
||||
let fix = Fix::automatic(Edit::deletion(func.end(), decorator.end()));
|
||||
let fix = Fix::always_applies(Edit::deletion(func.end(), decorator.end()));
|
||||
pytest_fixture_parentheses(
|
||||
checker,
|
||||
decorator,
|
||||
|
@ -735,7 +735,7 @@ fn check_fixture_decorator(checker: &mut Checker, func_name: &str, decorator: &D
|
|||
edits::Parentheses::Preserve,
|
||||
checker.locator().contents(),
|
||||
)
|
||||
.map(Fix::suggested)
|
||||
.map(Fix::sometimes_applies)
|
||||
});
|
||||
}
|
||||
checker.diagnostics.push(diagnostic);
|
||||
|
@ -746,7 +746,7 @@ fn check_fixture_decorator(checker: &mut Checker, func_name: &str, decorator: &D
|
|||
_ => {
|
||||
if checker.enabled(Rule::PytestFixtureIncorrectParenthesesStyle) {
|
||||
if checker.settings.flake8_pytest_style.fixture_parentheses {
|
||||
let fix = Fix::automatic(Edit::insertion(
|
||||
let fix = Fix::always_applies(Edit::insertion(
|
||||
Parentheses::Empty.to_string(),
|
||||
decorator.end(),
|
||||
));
|
||||
|
@ -839,9 +839,9 @@ fn check_fixture_returns(
|
|||
))
|
||||
});
|
||||
if let Some(return_type_edit) = return_type_edit {
|
||||
diagnostic.set_fix(Fix::automatic_edits(yield_edit, [return_type_edit]));
|
||||
diagnostic.set_fix(Fix::always_applies_edits(yield_edit, [return_type_edit]));
|
||||
} else {
|
||||
diagnostic.set_fix(Fix::automatic(yield_edit));
|
||||
diagnostic.set_fix(Fix::always_applies(yield_edit));
|
||||
}
|
||||
}
|
||||
checker.diagnostics.push(diagnostic);
|
||||
|
@ -914,7 +914,7 @@ fn check_fixture_marks(checker: &mut Checker, decorators: &[Decorator]) {
|
|||
Diagnostic::new(PytestUnnecessaryAsyncioMarkOnFixture, expr.range());
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
let range = checker.locator().full_lines_range(expr.range());
|
||||
diagnostic.set_fix(Fix::automatic(Edit::range_deletion(range)));
|
||||
diagnostic.set_fix(Fix::always_applies(Edit::range_deletion(range)));
|
||||
}
|
||||
checker.diagnostics.push(diagnostic);
|
||||
}
|
||||
|
@ -926,7 +926,7 @@ fn check_fixture_marks(checker: &mut Checker, decorators: &[Decorator]) {
|
|||
Diagnostic::new(PytestErroneousUseFixturesOnFixture, expr.range());
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
let line_range = checker.locator().full_lines_range(expr.range());
|
||||
diagnostic.set_fix(Fix::automatic(Edit::range_deletion(line_range)));
|
||||
diagnostic.set_fix(Fix::always_applies(Edit::range_deletion(line_range)));
|
||||
}
|
||||
checker.diagnostics.push(diagnostic);
|
||||
}
|
||||
|
|
|
@ -152,13 +152,13 @@ fn check_mark_parentheses(checker: &mut Checker, decorator: &Decorator, call_pat
|
|||
&& args.is_empty()
|
||||
&& keywords.is_empty()
|
||||
{
|
||||
let fix = Fix::automatic(Edit::deletion(func.end(), decorator.end()));
|
||||
let fix = Fix::always_applies(Edit::deletion(func.end(), decorator.end()));
|
||||
pytest_mark_parentheses(checker, decorator, call_path, fix, "", "()");
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
if checker.settings.flake8_pytest_style.mark_parentheses {
|
||||
let fix = Fix::automatic(Edit::insertion("()".to_string(), decorator.end()));
|
||||
let fix = Fix::always_applies(Edit::insertion("()".to_string(), decorator.end()));
|
||||
pytest_mark_parentheses(checker, decorator, call_path, fix, "()", "");
|
||||
}
|
||||
}
|
||||
|
@ -185,7 +185,9 @@ fn check_useless_usefixtures(checker: &mut Checker, decorator: &Decorator, call_
|
|||
if !has_parameters {
|
||||
let mut diagnostic = Diagnostic::new(PytestUseFixturesWithoutParameters, decorator.range());
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.set_fix(Fix::suggested(Edit::range_deletion(decorator.range())));
|
||||
diagnostic.set_fix(Fix::sometimes_applies(Edit::range_deletion(
|
||||
decorator.range(),
|
||||
)));
|
||||
}
|
||||
checker.diagnostics.push(diagnostic);
|
||||
}
|
||||
|
|
|
@ -352,7 +352,7 @@ fn check_names(checker: &mut Checker, decorator: &Decorator, expr: &Expr) {
|
|||
ctx: ExprContext::Load,
|
||||
range: TextRange::default(),
|
||||
});
|
||||
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::sometimes_applies(Edit::range_replacement(
|
||||
format!("({})", checker.generator().expr(&node)),
|
||||
name_range,
|
||||
)));
|
||||
|
@ -387,7 +387,7 @@ fn check_names(checker: &mut Checker, decorator: &Decorator, expr: &Expr) {
|
|||
ctx: ExprContext::Load,
|
||||
range: TextRange::default(),
|
||||
});
|
||||
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::sometimes_applies(Edit::range_replacement(
|
||||
checker.generator().expr(&node),
|
||||
name_range,
|
||||
)));
|
||||
|
@ -419,7 +419,7 @@ fn check_names(checker: &mut Checker, decorator: &Decorator, expr: &Expr) {
|
|||
ctx: ExprContext::Load,
|
||||
range: TextRange::default(),
|
||||
});
|
||||
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::sometimes_applies(Edit::range_replacement(
|
||||
checker.generator().expr(&node),
|
||||
expr.range(),
|
||||
)));
|
||||
|
@ -435,10 +435,9 @@ fn check_names(checker: &mut Checker, decorator: &Decorator, expr: &Expr) {
|
|||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
if let Some(content) = elts_to_csv(elts, checker.generator()) {
|
||||
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
|
||||
content,
|
||||
expr.range(),
|
||||
)));
|
||||
diagnostic.set_fix(Fix::sometimes_applies(
|
||||
Edit::range_replacement(content, expr.range()),
|
||||
));
|
||||
}
|
||||
}
|
||||
checker.diagnostics.push(diagnostic);
|
||||
|
@ -467,7 +466,7 @@ fn check_names(checker: &mut Checker, decorator: &Decorator, expr: &Expr) {
|
|||
ctx: ExprContext::Load,
|
||||
range: TextRange::default(),
|
||||
});
|
||||
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::sometimes_applies(Edit::range_replacement(
|
||||
format!("({})", checker.generator().expr(&node)),
|
||||
expr.range(),
|
||||
)));
|
||||
|
@ -483,10 +482,9 @@ fn check_names(checker: &mut Checker, decorator: &Decorator, expr: &Expr) {
|
|||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
if let Some(content) = elts_to_csv(elts, checker.generator()) {
|
||||
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
|
||||
content,
|
||||
expr.range(),
|
||||
)));
|
||||
diagnostic.set_fix(Fix::sometimes_applies(
|
||||
Edit::range_replacement(content, expr.range()),
|
||||
));
|
||||
}
|
||||
}
|
||||
checker.diagnostics.push(diagnostic);
|
||||
|
@ -598,8 +596,9 @@ fn check_duplicates(checker: &mut Checker, values: &Expr) {
|
|||
.comment_ranges()
|
||||
.intersects(deletion_range)
|
||||
{
|
||||
diagnostic
|
||||
.set_fix(Fix::suggested(Edit::range_deletion(deletion_range)));
|
||||
diagnostic.set_fix(Fix::sometimes_applies(Edit::range_deletion(
|
||||
deletion_range,
|
||||
)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -620,7 +619,7 @@ fn handle_single_name(checker: &mut Checker, expr: &Expr, value: &Expr) {
|
|||
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
let node = value.clone();
|
||||
diagnostic.set_fix(Fix::automatic(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::always_applies(Edit::range_replacement(
|
||||
checker.generator().expr(&node),
|
||||
expr.range(),
|
||||
)));
|
||||
|
|
|
@ -142,7 +142,7 @@ pub(crate) fn avoidable_escaped_quote(
|
|||
quote = quotes_settings.inline_quotes.opposite().as_char(),
|
||||
value = unescape_string(string_contents)
|
||||
);
|
||||
diagnostic.set_fix(Fix::automatic(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::always_applies(Edit::range_replacement(
|
||||
fixed_contents,
|
||||
tok_range,
|
||||
)));
|
||||
|
@ -216,7 +216,7 @@ pub(crate) fn avoidable_escaped_quote(
|
|||
tok_range,
|
||||
),
|
||||
));
|
||||
diagnostic.set_fix(Fix::automatic_edits(
|
||||
diagnostic.set_fix(Fix::always_applies_edits(
|
||||
fstring_start_edit,
|
||||
fstring_middle_and_end_edits,
|
||||
));
|
||||
|
|
|
@ -240,7 +240,7 @@ fn docstring(locator: &Locator, range: TextRange, settings: &LinterSettings) ->
|
|||
fixed_contents.push_str("e);
|
||||
fixed_contents.push_str(string_contents);
|
||||
fixed_contents.push_str("e);
|
||||
diagnostic.set_fix(Fix::automatic(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::always_applies(Edit::range_replacement(
|
||||
fixed_contents,
|
||||
range,
|
||||
)));
|
||||
|
@ -317,7 +317,7 @@ fn strings(
|
|||
fixed_contents.push_str(quote);
|
||||
fixed_contents.push_str(string_contents);
|
||||
fixed_contents.push_str(quote);
|
||||
diagnostic.set_fix(Fix::automatic(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::always_applies(Edit::range_replacement(
|
||||
fixed_contents,
|
||||
*range,
|
||||
)));
|
||||
|
@ -342,7 +342,7 @@ fn strings(
|
|||
fixed_contents.push(quote);
|
||||
fixed_contents.push_str(string_contents);
|
||||
fixed_contents.push(quote);
|
||||
diagnostic.set_fix(Fix::automatic(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::always_applies(Edit::range_replacement(
|
||||
fixed_contents,
|
||||
*range,
|
||||
)));
|
||||
|
|
|
@ -87,12 +87,12 @@ pub(crate) fn unnecessary_paren_on_raise_exception(checker: &mut Checker, expr:
|
|||
.next()
|
||||
.is_some_and(char::is_alphanumeric)
|
||||
{
|
||||
diagnostic.set_fix(Fix::automatic(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::always_applies(Edit::range_replacement(
|
||||
" ".to_string(),
|
||||
arguments.range(),
|
||||
)));
|
||||
} else {
|
||||
diagnostic.set_fix(Fix::automatic(Edit::range_deletion(arguments.range())));
|
||||
diagnostic.set_fix(Fix::always_applies(Edit::range_deletion(arguments.range())));
|
||||
}
|
||||
}
|
||||
checker.diagnostics.push(diagnostic);
|
||||
|
|
|
@ -346,7 +346,7 @@ fn unnecessary_return_none(checker: &mut Checker, stack: &Stack) {
|
|||
}
|
||||
let mut diagnostic = Diagnostic::new(UnnecessaryReturnNone, stmt.range);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.set_fix(Fix::automatic(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::always_applies(Edit::range_replacement(
|
||||
"return".to_string(),
|
||||
stmt.range(),
|
||||
)));
|
||||
|
@ -363,7 +363,7 @@ fn implicit_return_value(checker: &mut Checker, stack: &Stack) {
|
|||
}
|
||||
let mut diagnostic = Diagnostic::new(ImplicitReturnValue, stmt.range);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.set_fix(Fix::automatic(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::always_applies(Edit::range_replacement(
|
||||
"return None".to_string(),
|
||||
stmt.range,
|
||||
)));
|
||||
|
@ -415,7 +415,7 @@ fn implicit_return(checker: &mut Checker, stmt: &Stmt) {
|
|||
content.push_str(checker.stylist().line_ending().as_str());
|
||||
content.push_str(indent);
|
||||
content.push_str("return None");
|
||||
diagnostic.set_fix(Fix::suggested(Edit::insertion(
|
||||
diagnostic.set_fix(Fix::sometimes_applies(Edit::insertion(
|
||||
content,
|
||||
end_of_last_statement(stmt, checker.locator()),
|
||||
)));
|
||||
|
@ -437,7 +437,7 @@ fn implicit_return(checker: &mut Checker, stmt: &Stmt) {
|
|||
content.push_str(checker.stylist().line_ending().as_str());
|
||||
content.push_str(indent);
|
||||
content.push_str("return None");
|
||||
diagnostic.set_fix(Fix::suggested(Edit::insertion(
|
||||
diagnostic.set_fix(Fix::sometimes_applies(Edit::insertion(
|
||||
content,
|
||||
end_of_last_statement(stmt, checker.locator()),
|
||||
)));
|
||||
|
@ -473,7 +473,7 @@ fn implicit_return(checker: &mut Checker, stmt: &Stmt) {
|
|||
content.push_str(checker.stylist().line_ending().as_str());
|
||||
content.push_str(indent);
|
||||
content.push_str("return None");
|
||||
diagnostic.set_fix(Fix::suggested(Edit::insertion(
|
||||
diagnostic.set_fix(Fix::sometimes_applies(Edit::insertion(
|
||||
content,
|
||||
end_of_last_statement(stmt, checker.locator()),
|
||||
)));
|
||||
|
@ -567,7 +567,10 @@ fn unnecessary_assign(checker: &mut Checker, stack: &Stack) {
|
|||
),
|
||||
);
|
||||
|
||||
Ok(Fix::suggested_edits(replace_assign, [delete_return]))
|
||||
Ok(Fix::sometimes_applies_edits(
|
||||
replace_assign,
|
||||
[delete_return],
|
||||
))
|
||||
});
|
||||
}
|
||||
checker.diagnostics.push(diagnostic);
|
||||
|
|
|
@ -461,7 +461,7 @@ pub(crate) fn duplicate_isinstance_call(checker: &mut Checker, expr: &Expr) {
|
|||
|
||||
// Populate the `Fix`. Replace the _entire_ `BoolOp`. Note that if we have
|
||||
// multiple duplicates, the fixes will conflict.
|
||||
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::sometimes_applies(Edit::range_replacement(
|
||||
checker.generator().expr(&bool_op),
|
||||
expr.range(),
|
||||
)));
|
||||
|
@ -582,7 +582,7 @@ pub(crate) fn compare_with_tuple(checker: &mut Checker, expr: &Expr) {
|
|||
};
|
||||
node.into()
|
||||
};
|
||||
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::sometimes_applies(Edit::range_replacement(
|
||||
checker.generator().expr(&in_expr),
|
||||
expr.range(),
|
||||
)));
|
||||
|
@ -639,7 +639,7 @@ pub(crate) fn expr_and_not_expr(checker: &mut Checker, expr: &Expr) {
|
|||
expr.range(),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::sometimes_applies(Edit::range_replacement(
|
||||
"False".to_string(),
|
||||
expr.range(),
|
||||
)));
|
||||
|
@ -698,7 +698,7 @@ pub(crate) fn expr_or_not_expr(checker: &mut Checker, expr: &Expr) {
|
|||
expr.range(),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::sometimes_applies(Edit::range_replacement(
|
||||
"True".to_string(),
|
||||
expr.range(),
|
||||
)));
|
||||
|
@ -851,7 +851,7 @@ pub(crate) fn expr_or_true(checker: &mut Checker, expr: &Expr) {
|
|||
edit.range(),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.set_fix(Fix::suggested(edit));
|
||||
diagnostic.set_fix(Fix::sometimes_applies(edit));
|
||||
}
|
||||
checker.diagnostics.push(diagnostic);
|
||||
}
|
||||
|
@ -868,7 +868,7 @@ pub(crate) fn expr_and_false(checker: &mut Checker, expr: &Expr) {
|
|||
edit.range(),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.set_fix(Fix::suggested(edit));
|
||||
diagnostic.set_fix(Fix::sometimes_applies(edit));
|
||||
}
|
||||
checker.diagnostics.push(diagnostic);
|
||||
}
|
||||
|
|
|
@ -217,7 +217,7 @@ fn check_os_environ_subscript(checker: &mut Checker, expr: &Expr) {
|
|||
range: TextRange::default(),
|
||||
};
|
||||
let new_env_var = node.into();
|
||||
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::sometimes_applies(Edit::range_replacement(
|
||||
checker.generator().expr(&new_env_var),
|
||||
slice.range(),
|
||||
)));
|
||||
|
@ -276,7 +276,7 @@ pub(crate) fn dict_get_with_none_default(checker: &mut Checker, expr: &Expr) {
|
|||
);
|
||||
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.set_fix(Fix::automatic(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::always_applies(Edit::range_replacement(
|
||||
expected,
|
||||
expr.range(),
|
||||
)));
|
||||
|
|
|
@ -159,7 +159,7 @@ pub(crate) fn if_expr_with_true_false(
|
|||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
if test.is_compare_expr() {
|
||||
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::sometimes_applies(Edit::range_replacement(
|
||||
checker
|
||||
.locator()
|
||||
.slice(
|
||||
|
@ -175,7 +175,7 @@ pub(crate) fn if_expr_with_true_false(
|
|||
expr.range(),
|
||||
)));
|
||||
} else if checker.semantic().is_builtin("bool") {
|
||||
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::sometimes_applies(Edit::range_replacement(
|
||||
checker.generator().expr(
|
||||
&ast::ExprCall {
|
||||
func: Box::new(
|
||||
|
@ -216,7 +216,7 @@ pub(crate) fn if_expr_with_false_true(
|
|||
|
||||
let mut diagnostic = Diagnostic::new(IfExprWithFalseTrue, expr.range());
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::sometimes_applies(Edit::range_replacement(
|
||||
checker.generator().expr(
|
||||
&ast::ExprUnaryOp {
|
||||
op: UnaryOp::Not,
|
||||
|
@ -279,7 +279,7 @@ pub(crate) fn twisted_arms_in_ifexpr(
|
|||
orelse: Box::new(node),
|
||||
range: TextRange::default(),
|
||||
};
|
||||
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::sometimes_applies(Edit::range_replacement(
|
||||
checker.generator().expr(&node3.into()),
|
||||
expr.range(),
|
||||
)));
|
||||
|
|
|
@ -182,7 +182,7 @@ pub(crate) fn negation_with_equal_op(
|
|||
comparators: comparators.clone(),
|
||||
range: TextRange::default(),
|
||||
};
|
||||
diagnostic.set_fix(Fix::automatic(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::always_applies(Edit::range_replacement(
|
||||
checker.generator().expr(&node.into()),
|
||||
expr.range(),
|
||||
)));
|
||||
|
@ -239,7 +239,7 @@ pub(crate) fn negation_with_not_equal_op(
|
|||
comparators: comparators.clone(),
|
||||
range: TextRange::default(),
|
||||
};
|
||||
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::sometimes_applies(Edit::range_replacement(
|
||||
checker.generator().expr(&node.into()),
|
||||
expr.range(),
|
||||
)));
|
||||
|
@ -272,7 +272,7 @@ pub(crate) fn double_negation(checker: &mut Checker, expr: &Expr, op: UnaryOp, o
|
|||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
if checker.semantic().in_boolean_test() {
|
||||
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::sometimes_applies(Edit::range_replacement(
|
||||
checker.locator().slice(operand.as_ref()).to_string(),
|
||||
expr.range(),
|
||||
)));
|
||||
|
@ -291,7 +291,7 @@ pub(crate) fn double_negation(checker: &mut Checker, expr: &Expr, op: UnaryOp, o
|
|||
},
|
||||
range: TextRange::default(),
|
||||
};
|
||||
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::sometimes_applies(Edit::range_replacement(
|
||||
checker.generator().expr(&node1.into()),
|
||||
expr.range(),
|
||||
)));
|
||||
|
|
|
@ -145,7 +145,7 @@ pub(crate) fn multiple_with_statements(
|
|||
checker.settings.tab_size,
|
||||
)
|
||||
}) {
|
||||
diagnostic.set_fix(Fix::suggested(edit));
|
||||
diagnostic.set_fix(Fix::sometimes_applies(edit));
|
||||
}
|
||||
}
|
||||
Err(err) => error!("Failed to fix nested with: {err}"),
|
||||
|
|
|
@ -123,7 +123,7 @@ pub(crate) fn nested_if_statements(
|
|||
checker.settings.tab_size,
|
||||
)
|
||||
}) {
|
||||
diagnostic.set_fix(Fix::suggested(edit));
|
||||
diagnostic.set_fix(Fix::sometimes_applies(edit));
|
||||
}
|
||||
}
|
||||
Err(err) => error!("Failed to fix nested if: {err}"),
|
||||
|
|
|
@ -186,7 +186,7 @@ pub(crate) fn use_dict_get_with_default(checker: &mut Checker, stmt_if: &ast::St
|
|||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
if !checker.indexer().has_comments(stmt_if, checker.locator()) {
|
||||
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::sometimes_applies(Edit::range_replacement(
|
||||
contents,
|
||||
stmt_if.range(),
|
||||
)));
|
||||
|
|
|
@ -145,7 +145,7 @@ pub(crate) fn use_ternary_operator(checker: &mut Checker, stmt: &Stmt) {
|
|||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
if !checker.indexer().has_comments(stmt, checker.locator()) {
|
||||
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::sometimes_applies(Edit::range_replacement(
|
||||
contents,
|
||||
stmt.range(),
|
||||
)));
|
||||
|
|
|
@ -128,12 +128,12 @@ fn key_in_dict(
|
|||
.next()
|
||||
.is_some_and(|char| char.is_ascii_alphabetic())
|
||||
{
|
||||
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::sometimes_applies(Edit::range_replacement(
|
||||
" ".to_string(),
|
||||
range,
|
||||
)));
|
||||
} else {
|
||||
diagnostic.set_fix(Fix::suggested(Edit::range_deletion(range)));
|
||||
diagnostic.set_fix(Fix::sometimes_applies(Edit::range_deletion(range)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -112,7 +112,7 @@ pub(crate) fn needless_bool(checker: &mut Checker, stmt: &Stmt) {
|
|||
value: Some(Box::new(if_test.clone())),
|
||||
range: TextRange::default(),
|
||||
};
|
||||
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::sometimes_applies(Edit::range_replacement(
|
||||
checker.generator().stmt(&node.into()),
|
||||
range,
|
||||
)));
|
||||
|
@ -137,7 +137,7 @@ pub(crate) fn needless_bool(checker: &mut Checker, stmt: &Stmt) {
|
|||
value: Some(Box::new(node1.into())),
|
||||
range: TextRange::default(),
|
||||
};
|
||||
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::sometimes_applies(Edit::range_replacement(
|
||||
checker.generator().stmt(&node2.into()),
|
||||
range,
|
||||
)));
|
||||
|
|
|
@ -115,7 +115,7 @@ pub(crate) fn convert_for_loop_to_any_all(checker: &mut Checker, stmt: &Stmt) {
|
|||
TextRange::new(stmt.start(), terminal.stmt.end()),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) && checker.semantic().is_builtin("any") {
|
||||
diagnostic.set_fix(Fix::suggested(Edit::replacement(
|
||||
diagnostic.set_fix(Fix::sometimes_applies(Edit::replacement(
|
||||
contents,
|
||||
stmt.start(),
|
||||
terminal.stmt.end(),
|
||||
|
@ -201,7 +201,7 @@ pub(crate) fn convert_for_loop_to_any_all(checker: &mut Checker, stmt: &Stmt) {
|
|||
TextRange::new(stmt.start(), terminal.stmt.end()),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) && checker.semantic().is_builtin("all") {
|
||||
diagnostic.set_fix(Fix::suggested(Edit::replacement(
|
||||
diagnostic.set_fix(Fix::sometimes_applies(Edit::replacement(
|
||||
contents,
|
||||
stmt.start(),
|
||||
terminal.stmt.end(),
|
||||
|
|
|
@ -148,7 +148,7 @@ pub(crate) fn suppressible_exception(
|
|||
);
|
||||
let remove_handler =
|
||||
Edit::range_deletion(checker.locator().full_lines_range(*range));
|
||||
Ok(Fix::suggested_edits(
|
||||
Ok(Fix::sometimes_applies_edits(
|
||||
import_edit,
|
||||
[replace_try, remove_handler],
|
||||
))
|
||||
|
|
|
@ -194,7 +194,7 @@ pub(crate) fn yoda_conditions(
|
|||
expr.range(),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.set_fix(Fix::automatic(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::always_applies(Edit::range_replacement(
|
||||
pad(suggestion, expr.range(), checker.locator()),
|
||||
expr.range(),
|
||||
)));
|
||||
|
|
|
@ -103,7 +103,7 @@ fn fix_banned_relative_import(
|
|||
range: TextRange::default(),
|
||||
};
|
||||
let content = generator.stmt(&node.into());
|
||||
Some(Fix::suggested(Edit::range_replacement(
|
||||
Some(Fix::sometimes_applies(Edit::range_replacement(
|
||||
content,
|
||||
stmt.range(),
|
||||
)))
|
||||
|
|
|
@ -319,7 +319,7 @@ fn directive_errors(
|
|||
);
|
||||
|
||||
if settings.rules.should_fix(Rule::InvalidTodoCapitalization) {
|
||||
diagnostic.set_fix(Fix::automatic(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::always_applies(Edit::range_replacement(
|
||||
"TODO".to_string(),
|
||||
directive.range,
|
||||
)));
|
||||
|
|
|
@ -61,7 +61,7 @@ pub(crate) fn empty_type_checking_block(checker: &mut Checker, stmt: &ast::StmtI
|
|||
let stmt = checker.semantic().current_statement();
|
||||
let parent = checker.semantic().current_statement_parent();
|
||||
let edit = fix::edits::delete_stmt(stmt, parent, checker.locator(), checker.indexer());
|
||||
diagnostic.set_fix(Fix::automatic(edit).isolate(Checker::isolation(
|
||||
diagnostic.set_fix(Fix::always_applies(edit).isolate(Checker::isolation(
|
||||
checker.semantic().current_statement_parent_id(),
|
||||
)));
|
||||
}
|
||||
|
|
|
@ -235,7 +235,7 @@ fn fix_imports(checker: &Checker, node_id: NodeId, imports: &[ImportBinding]) ->
|
|||
)?;
|
||||
|
||||
Ok(
|
||||
Fix::suggested_edits(remove_import_edit, add_import_edit.into_edits()).isolate(
|
||||
Fix::sometimes_applies_edits(remove_import_edit, add_import_edit.into_edits()).isolate(
|
||||
Checker::isolation(checker.semantic().parent_statement_id(node_id)),
|
||||
),
|
||||
)
|
||||
|
|
|
@ -486,7 +486,7 @@ fn fix_imports(checker: &Checker, node_id: NodeId, imports: &[ImportBinding]) ->
|
|||
)?;
|
||||
|
||||
Ok(
|
||||
Fix::suggested_edits(remove_import_edit, add_import_edit.into_edits()).isolate(
|
||||
Fix::sometimes_applies_edits(remove_import_edit, add_import_edit.into_edits()).isolate(
|
||||
Checker::isolation(checker.semantic().parent_statement_id(node_id)),
|
||||
),
|
||||
)
|
||||
|
|
|
@ -77,7 +77,7 @@ pub(crate) fn path_constructor_current_directory(checker: &mut Checker, expr: &E
|
|||
if matches!(value.as_str(), "" | ".") {
|
||||
let mut diagnostic = Diagnostic::new(PathConstructorCurrentDirectory, *range);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.set_fix(Fix::automatic(Edit::range_deletion(*range)));
|
||||
diagnostic.set_fix(Fix::always_applies(Edit::range_deletion(*range)));
|
||||
}
|
||||
checker.diagnostics.push(diagnostic);
|
||||
}
|
||||
|
|
|
@ -155,7 +155,7 @@ pub(crate) fn static_join_to_fstring(checker: &mut Checker, expr: &Expr, joiner:
|
|||
expr.range(),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::sometimes_applies(Edit::range_replacement(
|
||||
pad(contents, expr.range(), checker.locator()),
|
||||
expr.range(),
|
||||
)));
|
||||
|
|
|
@ -117,7 +117,7 @@ fn add_required_import(
|
|||
TextRange::default(),
|
||||
);
|
||||
if settings.rules.should_fix(Rule::MissingRequiredImport) {
|
||||
diagnostic.set_fix(Fix::automatic(
|
||||
diagnostic.set_fix(Fix::always_applies(
|
||||
Importer::new(python_ast, locator, stylist)
|
||||
.add_import(required_import, TextSize::default()),
|
||||
));
|
||||
|
|
|
@ -139,7 +139,7 @@ pub(crate) fn organize_imports(
|
|||
|
||||
let mut diagnostic = Diagnostic::new(UnsortedImports, range);
|
||||
if settings.rules.should_fix(diagnostic.kind.rule()) {
|
||||
diagnostic.set_fix(Fix::automatic(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::always_applies(Edit::range_replacement(
|
||||
indent(&expected, indentation).to_string(),
|
||||
range,
|
||||
)));
|
||||
|
|
|
@ -84,7 +84,10 @@ pub(crate) fn deprecated_function(checker: &mut Checker, expr: &Expr) {
|
|||
checker.semantic(),
|
||||
)?;
|
||||
let replacement_edit = Edit::range_replacement(binding, expr.range());
|
||||
Ok(Fix::suggested_edits(import_edit, [replacement_edit]))
|
||||
Ok(Fix::sometimes_applies_edits(
|
||||
import_edit,
|
||||
[replacement_edit],
|
||||
))
|
||||
});
|
||||
}
|
||||
checker.diagnostics.push(diagnostic);
|
||||
|
|
|
@ -80,7 +80,7 @@ pub(crate) fn deprecated_type_alias(checker: &mut Checker, expr: &Expr) {
|
|||
_ => type_name,
|
||||
};
|
||||
if checker.semantic().is_builtin(type_name) {
|
||||
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
|
||||
diagnostic.set_fix(Fix::sometimes_applies(Edit::range_replacement(
|
||||
type_name.to_string(),
|
||||
expr.range(),
|
||||
)));
|
||||
|
|
|
@ -135,5 +135,8 @@ fn convert_inplace_argument_to_assignment(
|
|||
)
|
||||
.ok()?;
|
||||
|
||||
Some(Fix::suggested_edits(insert_assignment, [remove_argument]))
|
||||
Some(Fix::sometimes_applies_edits(
|
||||
insert_assignment,
|
||||
[remove_argument],
|
||||
))
|
||||
}
|
||||
|
|
|
@ -110,7 +110,10 @@ pub(crate) fn incorrect_dict_iterator(checker: &mut Checker, stmt_for: &ast::Stm
|
|||
),
|
||||
stmt_for.target.range(),
|
||||
);
|
||||
diagnostic.set_fix(Fix::suggested_edits(replace_attribute, [replace_target]));
|
||||
diagnostic.set_fix(Fix::sometimes_applies_edits(
|
||||
replace_attribute,
|
||||
[replace_target],
|
||||
));
|
||||
}
|
||||
checker.diagnostics.push(diagnostic);
|
||||
}
|
||||
|
@ -132,7 +135,10 @@ pub(crate) fn incorrect_dict_iterator(checker: &mut Checker, stmt_for: &ast::Stm
|
|||
),
|
||||
stmt_for.target.range(),
|
||||
);
|
||||
diagnostic.set_fix(Fix::suggested_edits(replace_attribute, [replace_target]));
|
||||
diagnostic.set_fix(Fix::sometimes_applies_edits(
|
||||
replace_attribute,
|
||||
[replace_target],
|
||||
));
|
||||
}
|
||||
checker.diagnostics.push(diagnostic);
|
||||
}
|
||||
|
|
|
@ -135,7 +135,7 @@ pub(crate) fn unnecessary_list_cast(checker: &mut Checker, iter: &Expr) {
|
|||
|
||||
/// Generate a [`Fix`] to remove a `list` cast from an expression.
|
||||
fn remove_cast(list_range: TextRange, iterable_range: TextRange) -> Fix {
|
||||
Fix::automatic_edits(
|
||||
Fix::always_applies_edits(
|
||||
Edit::deletion(list_range.start(), iterable_range.start()),
|
||||
[Edit::deletion(iterable_range.end(), list_range.end())],
|
||||
)
|
||||
|
|
|
@ -170,7 +170,7 @@ pub(crate) fn compound_statements(
|
|||
let mut diagnostic =
|
||||
Diagnostic::new(UselessSemicolon, TextRange::new(start, end));
|
||||
if settings.rules.should_fix(Rule::UselessSemicolon) {
|
||||
diagnostic.set_fix(Fix::automatic(Edit::deletion(
|
||||
diagnostic.set_fix(Fix::always_applies(Edit::deletion(
|
||||
indexer
|
||||
.preceded_by_continuations(start, locator)
|
||||
.unwrap_or(start),
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue