mirror of https://github.com/astral-sh/ruff
Apply fix to all errors in E711 and E712 autofix (#1238)
This commit is contained in:
parent
854cd14842
commit
630b4b627d
|
|
@ -35,12 +35,4 @@ impl Fix {
|
||||||
end_location: at,
|
end_location: at,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn dummy(location: Location) -> Self {
|
|
||||||
Self {
|
|
||||||
content: String::new(),
|
|
||||||
location,
|
|
||||||
end_location: location,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -59,24 +59,21 @@ pub fn literal_comparisons(
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if matches!(op, Cmpop::Eq) {
|
if matches!(op, Cmpop::Eq) {
|
||||||
let mut check = Check::new(
|
let check = Check::new(
|
||||||
CheckKind::NoneComparison(RejectedCmpop::Eq),
|
CheckKind::NoneComparison(RejectedCmpop::Eq),
|
||||||
Range::from_located(comparator),
|
Range::from_located(comparator),
|
||||||
);
|
);
|
||||||
if checker.patch(check.kind.code()) {
|
if checker.patch(check.kind.code()) {
|
||||||
// Dummy replacement
|
|
||||||
check.amend(Fix::dummy(expr.location));
|
|
||||||
bad_ops.insert(0, Cmpop::Is);
|
bad_ops.insert(0, Cmpop::Is);
|
||||||
}
|
}
|
||||||
checks.push(check);
|
checks.push(check);
|
||||||
}
|
}
|
||||||
if matches!(op, Cmpop::NotEq) {
|
if matches!(op, Cmpop::NotEq) {
|
||||||
let mut check = Check::new(
|
let check = Check::new(
|
||||||
CheckKind::NoneComparison(RejectedCmpop::NotEq),
|
CheckKind::NoneComparison(RejectedCmpop::NotEq),
|
||||||
Range::from_located(comparator),
|
Range::from_located(comparator),
|
||||||
);
|
);
|
||||||
if checker.patch(check.kind.code()) {
|
if checker.patch(check.kind.code()) {
|
||||||
check.amend(Fix::dummy(expr.location));
|
|
||||||
bad_ops.insert(0, Cmpop::IsNot);
|
bad_ops.insert(0, Cmpop::IsNot);
|
||||||
}
|
}
|
||||||
checks.push(check);
|
checks.push(check);
|
||||||
|
|
@ -90,23 +87,21 @@ pub fn literal_comparisons(
|
||||||
} = comparator.node
|
} = comparator.node
|
||||||
{
|
{
|
||||||
if matches!(op, Cmpop::Eq) {
|
if matches!(op, Cmpop::Eq) {
|
||||||
let mut check = Check::new(
|
let check = Check::new(
|
||||||
CheckKind::TrueFalseComparison(value, RejectedCmpop::Eq),
|
CheckKind::TrueFalseComparison(value, RejectedCmpop::Eq),
|
||||||
Range::from_located(comparator),
|
Range::from_located(comparator),
|
||||||
);
|
);
|
||||||
if checker.patch(check.kind.code()) {
|
if checker.patch(check.kind.code()) {
|
||||||
check.amend(Fix::dummy(expr.location));
|
|
||||||
bad_ops.insert(0, Cmpop::Is);
|
bad_ops.insert(0, Cmpop::Is);
|
||||||
}
|
}
|
||||||
checks.push(check);
|
checks.push(check);
|
||||||
}
|
}
|
||||||
if matches!(op, Cmpop::NotEq) {
|
if matches!(op, Cmpop::NotEq) {
|
||||||
let mut check = Check::new(
|
let check = Check::new(
|
||||||
CheckKind::TrueFalseComparison(value, RejectedCmpop::NotEq),
|
CheckKind::TrueFalseComparison(value, RejectedCmpop::NotEq),
|
||||||
Range::from_located(comparator),
|
Range::from_located(comparator),
|
||||||
);
|
);
|
||||||
if checker.patch(check.kind.code()) {
|
if checker.patch(check.kind.code()) {
|
||||||
check.amend(Fix::dummy(expr.location));
|
|
||||||
bad_ops.insert(0, Cmpop::IsNot);
|
bad_ops.insert(0, Cmpop::IsNot);
|
||||||
}
|
}
|
||||||
checks.push(check);
|
checks.push(check);
|
||||||
|
|
@ -126,23 +121,21 @@ pub fn literal_comparisons(
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if matches!(op, Cmpop::Eq) {
|
if matches!(op, Cmpop::Eq) {
|
||||||
let mut check = Check::new(
|
let check = Check::new(
|
||||||
CheckKind::NoneComparison(RejectedCmpop::Eq),
|
CheckKind::NoneComparison(RejectedCmpop::Eq),
|
||||||
Range::from_located(comparator),
|
Range::from_located(comparator),
|
||||||
);
|
);
|
||||||
if checker.patch(check.kind.code()) {
|
if checker.patch(check.kind.code()) {
|
||||||
check.amend(Fix::dummy(expr.location));
|
|
||||||
bad_ops.insert(idx, Cmpop::Is);
|
bad_ops.insert(idx, Cmpop::Is);
|
||||||
}
|
}
|
||||||
checks.push(check);
|
checks.push(check);
|
||||||
}
|
}
|
||||||
if matches!(op, Cmpop::NotEq) {
|
if matches!(op, Cmpop::NotEq) {
|
||||||
let mut check = Check::new(
|
let check = Check::new(
|
||||||
CheckKind::NoneComparison(RejectedCmpop::NotEq),
|
CheckKind::NoneComparison(RejectedCmpop::NotEq),
|
||||||
Range::from_located(comparator),
|
Range::from_located(comparator),
|
||||||
);
|
);
|
||||||
if checker.patch(check.kind.code()) {
|
if checker.patch(check.kind.code()) {
|
||||||
check.amend(Fix::dummy(expr.location));
|
|
||||||
bad_ops.insert(idx, Cmpop::IsNot);
|
bad_ops.insert(idx, Cmpop::IsNot);
|
||||||
}
|
}
|
||||||
checks.push(check);
|
checks.push(check);
|
||||||
|
|
@ -156,23 +149,21 @@ pub fn literal_comparisons(
|
||||||
} = comparator.node
|
} = comparator.node
|
||||||
{
|
{
|
||||||
if matches!(op, Cmpop::Eq) {
|
if matches!(op, Cmpop::Eq) {
|
||||||
let mut check = Check::new(
|
let check = Check::new(
|
||||||
CheckKind::TrueFalseComparison(value, RejectedCmpop::Eq),
|
CheckKind::TrueFalseComparison(value, RejectedCmpop::Eq),
|
||||||
Range::from_located(comparator),
|
Range::from_located(comparator),
|
||||||
);
|
);
|
||||||
if checker.patch(check.kind.code()) {
|
if checker.patch(check.kind.code()) {
|
||||||
check.amend(Fix::dummy(expr.location));
|
|
||||||
bad_ops.insert(idx, Cmpop::Is);
|
bad_ops.insert(idx, Cmpop::Is);
|
||||||
}
|
}
|
||||||
checks.push(check);
|
checks.push(check);
|
||||||
}
|
}
|
||||||
if matches!(op, Cmpop::NotEq) {
|
if matches!(op, Cmpop::NotEq) {
|
||||||
let mut check = Check::new(
|
let check = Check::new(
|
||||||
CheckKind::TrueFalseComparison(value, RejectedCmpop::NotEq),
|
CheckKind::TrueFalseComparison(value, RejectedCmpop::NotEq),
|
||||||
Range::from_located(comparator),
|
Range::from_located(comparator),
|
||||||
);
|
);
|
||||||
if checker.patch(check.kind.code()) {
|
if checker.patch(check.kind.code()) {
|
||||||
check.amend(Fix::dummy(expr.location));
|
|
||||||
bad_ops.insert(idx, Cmpop::IsNot);
|
bad_ops.insert(idx, Cmpop::IsNot);
|
||||||
}
|
}
|
||||||
checks.push(check);
|
checks.push(check);
|
||||||
|
|
@ -190,9 +181,9 @@ pub fn literal_comparisons(
|
||||||
.cloned()
|
.cloned()
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
if let Some(content) = compare(left, &ops, comparators) {
|
if let Some(content) = compare(left, &ops, comparators) {
|
||||||
if let Some(check) = checks.last_mut() {
|
for check in &mut checks {
|
||||||
check.fix = Some(Fix::replacement(
|
check.amend(Fix::replacement(
|
||||||
content,
|
content.to_string(),
|
||||||
expr.location,
|
expr.location,
|
||||||
expr.end_location.unwrap(),
|
expr.end_location.unwrap(),
|
||||||
));
|
));
|
||||||
|
|
|
||||||
|
|
@ -139,13 +139,13 @@ expression: checks
|
||||||
row: 26
|
row: 26
|
||||||
column: 12
|
column: 12
|
||||||
fix:
|
fix:
|
||||||
content: ""
|
content: x is None is not None
|
||||||
location:
|
location:
|
||||||
row: 26
|
row: 26
|
||||||
column: 3
|
column: 3
|
||||||
end_location:
|
end_location:
|
||||||
row: 26
|
row: 26
|
||||||
column: 3
|
column: 20
|
||||||
- kind:
|
- kind:
|
||||||
NoneComparison: NotEq
|
NoneComparison: NotEq
|
||||||
location:
|
location:
|
||||||
|
|
|
||||||
|
|
@ -175,13 +175,13 @@ expression: checks
|
||||||
row: 25
|
row: 25
|
||||||
column: 14
|
column: 14
|
||||||
fix:
|
fix:
|
||||||
content: ""
|
content: res is True is not False
|
||||||
location:
|
location:
|
||||||
row: 25
|
row: 25
|
||||||
column: 3
|
column: 3
|
||||||
end_location:
|
end_location:
|
||||||
row: 25
|
row: 25
|
||||||
column: 3
|
column: 23
|
||||||
- kind:
|
- kind:
|
||||||
TrueFalseComparison:
|
TrueFalseComparison:
|
||||||
- false
|
- false
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue