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,6 +59,8 @@ pub fn check_lines(
.map(|lineno| lineno - 1) .map(|lineno| lineno - 1)
.unwrap_or(lineno); .unwrap_or(lineno);
// Enforce unnecessary coding comments (U009).
if enforce_unnecessary_coding_comment {
if lineno < 2 { if lineno < 2 {
// PEP3120 makes utf-8 the default encoding. // PEP3120 makes utf-8 the default encoding.
if CODING_COMMENT_REGEX.is_match(line) { if CODING_COMMENT_REGEX.is_match(line) {
@ -78,6 +81,7 @@ pub fn check_lines(
line_checks.push(check); line_checks.push(check);
} }
} }
}
if enforce_noqa { if enforce_noqa {
noqa_directives noqa_directives
@ -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) {