-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[pygrep-hooks] Adds Check for Blanket
# noqa
(#1440)
- Loading branch information
Showing
12 changed files
with
152 additions
and
22 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
x = 1 # noqa | ||
x = 1 # NOQA:F401,W203 | ||
# noqa | ||
# NOQA | ||
# noqa:F401 | ||
# noqa:F401,W203 | ||
|
||
x = 1 | ||
x = 1 # noqa: F401, W203 | ||
# noqa: F401 | ||
# noqa: F401, W203 |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -726,6 +726,7 @@ | |
"PGH001", | ||
"PGH002", | ||
"PGH003", | ||
"PGH004", | ||
"PLC", | ||
"PLC0", | ||
"PLC04", | ||
|
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use once_cell::sync::Lazy; | ||
use regex::Regex; | ||
use rustpython_ast::Location; | ||
|
||
use crate::ast::types::Range; | ||
use crate::checks::{Check, CheckKind}; | ||
|
||
static BLANKET_NOQA_REGEX: Lazy<Regex> = | ||
Lazy::new(|| Regex::new(r"(?i)# noqa($|\s|:[^ ])").unwrap()); | ||
|
||
/// PGH004 - use of blanket noqa comments | ||
pub fn blanket_noqa(lineno: usize, line: &str) -> Option<Check> { | ||
BLANKET_NOQA_REGEX.find(line).map(|m| { | ||
Check::new( | ||
CheckKind::BlanketNOQA, | ||
Range { | ||
location: Location::new(lineno + 1, m.start()), | ||
end_location: Location::new(lineno + 1, m.end()), | ||
}, | ||
) | ||
}) | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
pub use blanket_noqa::blanket_noqa; | ||
pub use blanket_type_ignore::blanket_type_ignore; | ||
pub use deprecated_log_warn::deprecated_log_warn; | ||
pub use no_eval::no_eval; | ||
|
||
mod blanket_noqa; | ||
mod blanket_type_ignore; | ||
mod deprecated_log_warn; | ||
mod no_eval; |
53 changes: 53 additions & 0 deletions
53
src/pygrep_hooks/snapshots/ruff__pygrep_hooks__tests__PGH004_PGH004_0.py.snap
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
--- | ||
source: src/pygrep_hooks/mod.rs | ||
expression: checks | ||
--- | ||
- kind: BlanketNoqa | ||
location: | ||
row: 1 | ||
column: 7 | ||
end_location: | ||
row: 1 | ||
column: 13 | ||
fix: ~ | ||
- kind: BlanketNoqa | ||
location: | ||
row: 2 | ||
column: 7 | ||
end_location: | ||
row: 2 | ||
column: 15 | ||
fix: ~ | ||
- kind: BlanketNoqa | ||
location: | ||
row: 3 | ||
column: 0 | ||
end_location: | ||
row: 3 | ||
column: 6 | ||
fix: ~ | ||
- kind: BlanketNoqa | ||
location: | ||
row: 4 | ||
column: 0 | ||
end_location: | ||
row: 4 | ||
column: 6 | ||
fix: ~ | ||
- kind: BlanketNoqa | ||
location: | ||
row: 5 | ||
column: 0 | ||
end_location: | ||
row: 5 | ||
column: 8 | ||
fix: ~ | ||
- kind: BlanketNoqa | ||
location: | ||
row: 6 | ||
column: 0 | ||
end_location: | ||
row: 6 | ||
column: 8 | ||
fix: ~ | ||
|