Avoid flagging RUF100 as a RUF100 violation (#1305)

This commit is contained in:
Charlie Marsh 2022-12-20 17:40:10 -05:00 committed by GitHub
parent e7d40d435f
commit f40e4bcd14
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 44 additions and 4 deletions

View file

@ -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)

View file

@ -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),

View file

@ -38,6 +38,7 @@ mod tests {
&settings::Settings::for_rules(vec![
CheckCode::RUF100,
CheckCode::E501,
CheckCode::F401,
CheckCode::F841,
]),
)?;

View file

@ -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