Skip to content

Commit 8dd3811

Browse files
Use function range for reimplemented-operator diagnostics (#11271)
1 parent 894cd13 commit 8dd3811

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

crates/ruff_linter/src/rules/refurb/rules/reimplemented_operator.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use anyhow::Result;
55

66
use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation};
77
use ruff_macros::{derive_message_formats, violation};
8+
use ruff_python_ast::identifier::Identifier;
89
use ruff_python_ast::{self as ast, Expr, ExprSlice, ExprSubscript, ExprTuple, Parameters, Stmt};
910
use ruff_python_semantic::SemanticModel;
1011
use ruff_source_file::Locator;
@@ -118,7 +119,7 @@ impl Ranged for FunctionLike<'_> {
118119
fn range(&self) -> TextRange {
119120
match self {
120121
Self::Lambda(expr) => expr.range(),
121-
Self::Function(stmt) => stmt.range(),
122+
Self::Function(stmt) => stmt.identifier(),
122123
}
123124
}
124125
}

crates/ruff_linter/src/rules/refurb/snapshots/ruff_linter__rules__refurb__tests__FURB118_FURB118.py.snap

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -778,18 +778,18 @@ FURB118.py:33:17: FURB118 [*] Use `operator.itemgetter(slice(None))` instead of
778778
35 36 |
779779
36 37 | def op_not2(x):
780780

781-
FURB118.py:36:1: FURB118 Use `operator.not_` instead of defining a function
781+
FURB118.py:36:5: FURB118 Use `operator.not_` instead of defining a function
782782
|
783-
36 | / def op_not2(x):
784-
37 | | return not x
785-
| |________________^ FURB118
783+
36 | def op_not2(x):
784+
| ^^^^^^^ FURB118
785+
37 | return not x
786786
|
787787
= help: Replace with `operator.not_`
788788

789-
FURB118.py:40:1: FURB118 Use `operator.add` instead of defining a function
789+
FURB118.py:40:5: FURB118 Use `operator.add` instead of defining a function
790790
|
791-
40 | / def op_add2(x, y):
792-
41 | | return x + y
793-
| |________________^ FURB118
791+
40 | def op_add2(x, y):
792+
| ^^^^^^^ FURB118
793+
41 | return x + y
794794
|
795795
= help: Replace with `operator.add`

0 commit comments

Comments
 (0)