From 938ad9a39ee65e7306688aa402a40d1ce55a7b8f Mon Sep 17 00:00:00 2001 From: Harutaka Kawamura Date: Sat, 31 Dec 2022 21:43:03 +0900 Subject: [PATCH] Fix N818 range (#1503) --- src/checkers/ast.rs | 9 ++++++--- src/pep8_naming/checks.rs | 3 ++- .../ruff__pep8_naming__tests__N818_N818.py.snap | 12 ++++++------ 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/checkers/ast.rs b/src/checkers/ast.rs index e031b9ee79..8797dfee1f 100644 --- a/src/checkers/ast.rs +++ b/src/checkers/ast.rs @@ -582,9 +582,12 @@ where } if self.settings.enabled.contains(&CheckCode::N818) { - if let Some(check) = - pep8_naming::checks::error_suffix_on_exception_name(stmt, bases, name) - { + if let Some(check) = pep8_naming::checks::error_suffix_on_exception_name( + stmt, + bases, + name, + self.locator, + ) { self.add_check(check); } } diff --git a/src/pep8_naming/checks.rs b/src/pep8_naming/checks.rs index 6411faa653..4b44dea022 100644 --- a/src/pep8_naming/checks.rs +++ b/src/pep8_naming/checks.rs @@ -246,6 +246,7 @@ pub fn error_suffix_on_exception_name( class_def: &Stmt, bases: &[Expr], name: &str, + locator: &SourceCodeLocator, ) -> Option { if !bases.iter().any(|base| { if let ExprKind::Name { id, .. } = &base.node { @@ -262,6 +263,6 @@ pub fn error_suffix_on_exception_name( } Some(Check::new( CheckKind::ErrorSuffixOnExceptionName(name.to_string()), - Range::from_located(class_def), + identifier_range(class_def, locator), )) } diff --git a/src/pep8_naming/snapshots/ruff__pep8_naming__tests__N818_N818.py.snap b/src/pep8_naming/snapshots/ruff__pep8_naming__tests__N818_N818.py.snap index e7a50f3ff7..289e195cf0 100644 --- a/src/pep8_naming/snapshots/ruff__pep8_naming__tests__N818_N818.py.snap +++ b/src/pep8_naming/snapshots/ruff__pep8_naming__tests__N818_N818.py.snap @@ -6,20 +6,20 @@ expression: checks ErrorSuffixOnExceptionName: C location: row: 9 - column: 0 + column: 6 end_location: - row: 10 - column: 8 + row: 9 + column: 7 fix: ~ parent: ~ - kind: ErrorSuffixOnExceptionName: E location: row: 17 - column: 0 + column: 6 end_location: - row: 18 - column: 8 + row: 17 + column: 7 fix: ~ parent: ~