Avoid U009 violations when disabled (#650)

This commit is contained in:
Charlie Marsh 2022-11-07 16:36:39 -05:00 committed by GitHub
parent 16c5ac1e91
commit 1aafe31c00
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 22 additions and 18 deletions

View File

@ -40,6 +40,7 @@ pub fn check_lines(
settings: &Settings, settings: &Settings,
autofix: &fixer::Mode, autofix: &fixer::Mode,
) { ) {
let enforce_unnecessary_coding_comment = settings.enabled.contains(&CheckCode::U009);
let enforce_line_too_long = settings.enabled.contains(&CheckCode::E501); let enforce_line_too_long = settings.enabled.contains(&CheckCode::E501);
let enforce_noqa = settings.enabled.contains(&CheckCode::M001); let enforce_noqa = settings.enabled.contains(&CheckCode::M001);
@ -58,24 +59,27 @@ pub fn check_lines(
.map(|lineno| lineno - 1) .map(|lineno| lineno - 1)
.unwrap_or(lineno); .unwrap_or(lineno);
if lineno < 2 { // Enforce unnecessary coding comments (U009).
// PEP3120 makes utf-8 the default encoding. if enforce_unnecessary_coding_comment {
if CODING_COMMENT_REGEX.is_match(line) { if lineno < 2 {
let line_length = line.len(); // PEP3120 makes utf-8 the default encoding.
let mut check = Check::new( if CODING_COMMENT_REGEX.is_match(line) {
CheckKind::PEP3120UnnecessaryCodingComment, let line_length = line.len();
Range { let mut check = Check::new(
location: Location::new(lineno + 1, 0), CheckKind::PEP3120UnnecessaryCodingComment,
end_location: Location::new(lineno + 1, line_length + 1), Range {
}, location: Location::new(lineno + 1, 0),
); end_location: Location::new(lineno + 1, line_length + 1),
if autofix.patch() { },
check.amend(Fix::deletion( );
Location::new(lineno + 1, 0), if autofix.patch() {
Location::new(lineno + 1, line_length + 1), check.amend(Fix::deletion(
)); Location::new(lineno + 1, 0),
Location::new(lineno + 1, line_length + 1),
));
}
line_checks.push(check);
} }
line_checks.push(check);
} }
} }
@ -109,7 +113,7 @@ pub fn check_lines(
} }
} }
// Enforce line length. // Enforce line length violations (E501).
if enforce_line_too_long { if enforce_line_too_long {
let line_length = line.chars().count(); let line_length = line.chars().count();
if should_enforce_line_length(line, line_length, settings.line_length) { if should_enforce_line_length(line, line_length, settings.line_length) {