Skip to content

Commit

Permalink
Fix leftover whitespace when removing pass for PIE790 (#1612)
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarrmondragon committed Jan 4, 2023
1 parent 77692e4 commit 60359c6
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 81 deletions.
5 changes: 5 additions & 0 deletions resources/test/fixtures/flake8_pie/PIE790.py
Expand Up @@ -9,6 +9,11 @@ class Foo:
pass # PIE790


def multi_statement() -> None:
"""This is a function."""
pass; print("hello")


if foo:
pass
else:
Expand Down
14 changes: 10 additions & 4 deletions src/flake8_pie/plugins.rs
@@ -1,7 +1,9 @@
use log::error;
use rustc_hash::FxHashSet;
use rustpython_ast::{Constant, Expr, ExprKind, Stmt, StmtKind};

use crate::ast::types::Range;
use crate::autofix::helpers::delete_stmt;
use crate::autofix::Fix;
use crate::checkers::ast::Checker;
use crate::registry::{Check, CheckCode, CheckKind};
Expand All @@ -27,10 +29,14 @@ pub fn no_unnecessary_pass(checker: &mut Checker, body: &[Stmt]) {
let mut check =
Check::new(CheckKind::NoUnnecessaryPass, Range::from_located(pass_stmt));
if checker.patch(&CheckCode::PIE790) {
check.amend(Fix::deletion(
pass_stmt.location,
pass_stmt.end_location.unwrap(),
));
match delete_stmt(pass_stmt, None, &[], checker.locator) {
Ok(fix) => {
check.amend(fix);
}
Err(e) => {
error!("Failed to delete `pass` statement: {}", e);
}
}
}
checker.add_check(check);
}
Expand Down
Expand Up @@ -13,10 +13,10 @@ expression: checks
content: ""
location:
row: 4
column: 4
column: 0
end_location:
row: 4
column: 8
row: 5
column: 0
parent: ~
- kind: NoUnnecessaryPass
location:
Expand All @@ -29,138 +29,138 @@ expression: checks
content: ""
location:
row: 9
column: 4
column: 0
end_location:
row: 9
column: 8
row: 10
column: 0
parent: ~
- kind: NoUnnecessaryPass
location:
row: 16
row: 14
column: 4
end_location:
row: 16
row: 14
column: 8
fix:
content: ""
location:
row: 16
row: 14
column: 4
end_location:
row: 16
column: 8
row: 14
column: 10
parent: ~
- kind: NoUnnecessaryPass
location:
row: 23
row: 21
column: 4
end_location:
row: 23
row: 21
column: 8
fix:
content: ""
location:
row: 23
column: 4
row: 21
column: 0
end_location:
row: 23
column: 8
row: 22
column: 0
parent: ~
- kind: NoUnnecessaryPass
location:
row: 30
row: 28
column: 4
end_location:
row: 30
row: 28
column: 8
fix:
content: ""
location:
row: 30
column: 4
row: 28
column: 0
end_location:
row: 30
column: 8
row: 29
column: 0
parent: ~
- kind: NoUnnecessaryPass
location:
row: 37
row: 35
column: 4
end_location:
row: 37
row: 35
column: 8
fix:
content: ""
location:
row: 37
column: 4
row: 35
column: 0
end_location:
row: 37
column: 8
row: 36
column: 0
parent: ~
- kind: NoUnnecessaryPass
location:
row: 45
row: 42
column: 4
end_location:
row: 45
row: 42
column: 8
fix:
content: ""
location:
row: 45
column: 4
row: 42
column: 0
end_location:
row: 45
column: 8
row: 43
column: 0
parent: ~
- kind: NoUnnecessaryPass
location:
row: 53
row: 50
column: 4
end_location:
row: 53
row: 50
column: 8
fix:
content: ""
location:
row: 53
column: 4
row: 50
column: 0
end_location:
row: 53
column: 8
row: 51
column: 0
parent: ~
- kind: NoUnnecessaryPass
location:
row: 60
row: 58
column: 4
end_location:
row: 60
row: 58
column: 8
fix:
content: ""
location:
row: 60
column: 4
row: 58
column: 0
end_location:
row: 60
column: 8
row: 59
column: 0
parent: ~
- kind: NoUnnecessaryPass
location:
row: 69
row: 65
column: 4
end_location:
row: 69
row: 65
column: 8
fix:
content: ""
location:
row: 69
column: 4
row: 65
column: 0
end_location:
row: 69
column: 8
row: 66
column: 0
parent: ~
- kind: NoUnnecessaryPass
location:
Expand All @@ -173,42 +173,42 @@ expression: checks
content: ""
location:
row: 74
column: 4
column: 0
end_location:
row: 74
column: 8
row: 75
column: 0
parent: ~
- kind: NoUnnecessaryPass
location:
row: 78
row: 79
column: 4
end_location:
row: 78
row: 79
column: 8
fix:
content: ""
location:
row: 78
column: 4
row: 79
column: 0
end_location:
row: 78
column: 8
row: 80
column: 0
parent: ~
- kind: NoUnnecessaryPass
location:
row: 82
row: 83
column: 4
end_location:
row: 82
row: 83
column: 8
fix:
content: ""
location:
row: 82
column: 4
row: 83
column: 0
end_location:
row: 82
column: 8
row: 84
column: 0
parent: ~
- kind: NoUnnecessaryPass
location:
Expand All @@ -221,25 +221,41 @@ expression: checks
content: ""
location:
row: 87
column: 4
column: 0
end_location:
row: 87
column: 8
row: 88
column: 0
parent: ~
- kind: NoUnnecessaryPass
location:
row: 91
row: 92
column: 4
end_location:
row: 91
row: 92
column: 8
fix:
content: ""
location:
row: 91
column: 4
row: 92
column: 0
end_location:
row: 93
column: 0
parent: ~
- kind: NoUnnecessaryPass
location:
row: 96
column: 4
end_location:
row: 96
column: 8
fix:
content: ""
location:
row: 96
column: 0
end_location:
row: 91
column: 8
row: 97
column: 0
parent: ~

0 comments on commit 60359c6

Please sign in to comment.