From 8dd38110d9bd97cc1cbdcf747d2a0b566d374615 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Fri, 3 May 2024 16:11:02 -0400 Subject: [PATCH] Use function range for `reimplemented-operator` diagnostics (#11271) --- .../rules/refurb/rules/reimplemented_operator.rs | 3 ++- ...rules__refurb__tests__FURB118_FURB118.py.snap | 16 ++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/crates/ruff_linter/src/rules/refurb/rules/reimplemented_operator.rs b/crates/ruff_linter/src/rules/refurb/rules/reimplemented_operator.rs index 15dc329ae2cba..6fa0e91cf5225 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/reimplemented_operator.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/reimplemented_operator.rs @@ -5,6 +5,7 @@ use anyhow::Result; use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation}; use ruff_macros::{derive_message_formats, violation}; +use ruff_python_ast::identifier::Identifier; use ruff_python_ast::{self as ast, Expr, ExprSlice, ExprSubscript, ExprTuple, Parameters, Stmt}; use ruff_python_semantic::SemanticModel; use ruff_source_file::Locator; @@ -118,7 +119,7 @@ impl Ranged for FunctionLike<'_> { fn range(&self) -> TextRange { match self { Self::Lambda(expr) => expr.range(), - Self::Function(stmt) => stmt.range(), + Self::Function(stmt) => stmt.identifier(), } } } diff --git a/crates/ruff_linter/src/rules/refurb/snapshots/ruff_linter__rules__refurb__tests__FURB118_FURB118.py.snap b/crates/ruff_linter/src/rules/refurb/snapshots/ruff_linter__rules__refurb__tests__FURB118_FURB118.py.snap index 937bf2ec46317..daab20b991ae3 100644 --- a/crates/ruff_linter/src/rules/refurb/snapshots/ruff_linter__rules__refurb__tests__FURB118_FURB118.py.snap +++ b/crates/ruff_linter/src/rules/refurb/snapshots/ruff_linter__rules__refurb__tests__FURB118_FURB118.py.snap @@ -778,18 +778,18 @@ FURB118.py:33:17: FURB118 [*] Use `operator.itemgetter(slice(None))` instead of 35 36 | 36 37 | def op_not2(x): -FURB118.py:36:1: FURB118 Use `operator.not_` instead of defining a function +FURB118.py:36:5: FURB118 Use `operator.not_` instead of defining a function | -36 | / def op_not2(x): -37 | | return not x - | |________________^ FURB118 +36 | def op_not2(x): + | ^^^^^^^ FURB118 +37 | return not x | = help: Replace with `operator.not_` -FURB118.py:40:1: FURB118 Use `operator.add` instead of defining a function +FURB118.py:40:5: FURB118 Use `operator.add` instead of defining a function | -40 | / def op_add2(x, y): -41 | | return x + y - | |________________^ FURB118 +40 | def op_add2(x, y): + | ^^^^^^^ FURB118 +41 | return x + y | = help: Replace with `operator.add`