mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-28 04:44:51 +00:00
Avoid flagging RUF100 as a RUF100 violation (#1305)
This commit is contained in:
parent
e7d40d435f
commit
f40e4bcd14
4 changed files with 44 additions and 4 deletions
7
resources/test/fixtures/ruff/RUF100.py
vendored
7
resources/test/fixtures/ruff/RUF100.py
vendored
|
@ -79,3 +79,10 @@ _ = """Here's a source: https://github.com/ethereum/web3.py/blob/ffe59daf10edc19
|
|||
May raise:
|
||||
- DeserializationError if the abi string is invalid or abi or log topics/data do not match
|
||||
""" # noqa: E501
|
||||
|
||||
import collections # noqa
|
||||
import os # noqa: F401, RUF100
|
||||
import shelve # noqa: RUF100
|
||||
import sys # noqa: F401, RUF100
|
||||
|
||||
print(sys.path)
|
||||
|
|
|
@ -100,18 +100,32 @@ pub fn check_noqa(
|
|||
Directive::Codes(spaces, start, end, codes) => {
|
||||
let mut invalid_codes = vec![];
|
||||
let mut valid_codes = vec![];
|
||||
let mut self_ignore = false;
|
||||
for code in codes {
|
||||
let code = CODE_REDIRECTS.get(code).map_or(code, AsRef::as_ref);
|
||||
if matches.contains(&code) || settings.external.contains(code) {
|
||||
valid_codes.push(code.to_string());
|
||||
if code == CheckCode::RUF100.as_ref() {
|
||||
self_ignore = true;
|
||||
} else {
|
||||
invalid_codes.push(code.to_string());
|
||||
if matches.contains(&code) || settings.external.contains(code) {
|
||||
valid_codes.push(code);
|
||||
} else {
|
||||
invalid_codes.push(code);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if self_ignore {
|
||||
continue;
|
||||
}
|
||||
|
||||
if !invalid_codes.is_empty() {
|
||||
let mut check = Check::new(
|
||||
CheckKind::UnusedNOQA(Some(invalid_codes)),
|
||||
CheckKind::UnusedNOQA(Some(
|
||||
invalid_codes
|
||||
.iter()
|
||||
.map(|code| (*code).to_string())
|
||||
.collect(),
|
||||
)),
|
||||
Range {
|
||||
location: Location::new(row + 1, start),
|
||||
end_location: Location::new(row + 1, end),
|
||||
|
|
|
@ -38,6 +38,7 @@ mod tests {
|
|||
&settings::Settings::for_rules(vec![
|
||||
CheckCode::RUF100,
|
||||
CheckCode::E501,
|
||||
CheckCode::F401,
|
||||
CheckCode::F841,
|
||||
]),
|
||||
)?;
|
||||
|
|
|
@ -182,4 +182,22 @@ expression: checks
|
|||
end_location:
|
||||
row: 71
|
||||
column: 11
|
||||
- kind:
|
||||
UnusedImport:
|
||||
- shelve
|
||||
- false
|
||||
location:
|
||||
row: 85
|
||||
column: 7
|
||||
end_location:
|
||||
row: 85
|
||||
column: 13
|
||||
fix:
|
||||
content: ""
|
||||
location:
|
||||
row: 85
|
||||
column: 0
|
||||
end_location:
|
||||
row: 86
|
||||
column: 0
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue