Fix N818 range (#1503)

This commit is contained in:
Harutaka Kawamura 2022-12-31 21:43:03 +09:00 committed by GitHub
parent 14248cb8cb
commit 938ad9a39e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 10 deletions

View file

@ -582,9 +582,12 @@ where
} }
if self.settings.enabled.contains(&CheckCode::N818) { if self.settings.enabled.contains(&CheckCode::N818) {
if let Some(check) = if let Some(check) = pep8_naming::checks::error_suffix_on_exception_name(
pep8_naming::checks::error_suffix_on_exception_name(stmt, bases, name) stmt,
{ bases,
name,
self.locator,
) {
self.add_check(check); self.add_check(check);
} }
} }

View file

@ -246,6 +246,7 @@ pub fn error_suffix_on_exception_name(
class_def: &Stmt, class_def: &Stmt,
bases: &[Expr], bases: &[Expr],
name: &str, name: &str,
locator: &SourceCodeLocator,
) -> Option<Check> { ) -> Option<Check> {
if !bases.iter().any(|base| { if !bases.iter().any(|base| {
if let ExprKind::Name { id, .. } = &base.node { if let ExprKind::Name { id, .. } = &base.node {
@ -262,6 +263,6 @@ pub fn error_suffix_on_exception_name(
} }
Some(Check::new( Some(Check::new(
CheckKind::ErrorSuffixOnExceptionName(name.to_string()), CheckKind::ErrorSuffixOnExceptionName(name.to_string()),
Range::from_located(class_def), identifier_range(class_def, locator),
)) ))
} }

View file

@ -6,20 +6,20 @@ expression: checks
ErrorSuffixOnExceptionName: C ErrorSuffixOnExceptionName: C
location: location:
row: 9 row: 9
column: 0 column: 6
end_location: end_location:
row: 10 row: 9
column: 8 column: 7
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
ErrorSuffixOnExceptionName: E ErrorSuffixOnExceptionName: E
location: location:
row: 17 row: 17
column: 0 column: 6
end_location: end_location:
row: 18 row: 17
column: 8 column: 7
fix: ~ fix: ~
parent: ~ parent: ~