diff --git a/crates/ruff/src/rules/pydocstyle/rules/sections.rs b/crates/ruff/src/rules/pydocstyle/rules/sections.rs index f20f8a0b55..d0c7ffe80d 100644 --- a/crates/ruff/src/rules/pydocstyle/rules/sections.rs +++ b/crates/ruff/src/rules/pydocstyle/rules/sections.rs @@ -5,6 +5,7 @@ use ruff_macros::{define_violation, derive_message_formats}; use rustc_hash::FxHashSet; use rustpython_parser::ast::StmtKind; +use crate::ast::helpers::identifier_range; use crate::ast::types::Range; use crate::ast::whitespace::LinesWithTrailingNewline; use crate::ast::{cast, whitespace}; @@ -837,7 +838,7 @@ fn missing_args(checker: &mut Checker, docstring: &Docstring, docstrings_args: & let names = missing_arg_names.into_iter().sorted().collect(); checker.diagnostics.push(Diagnostic::new( UndocumentedParam { names }, - Range::from_located(parent), + identifier_range(parent, checker.locator), )); } } diff --git a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D417_sections.py.snap b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D417_sections.py.snap index 59a9c04fb4..d9e0a42252 100644 --- a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D417_sections.py.snap +++ b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D417_sections.py.snap @@ -8,10 +8,10 @@ expression: diagnostics - y location: row: 283 - column: 4 + column: 8 end_location: - row: 293 - column: 16 + row: 283 + column: 11 fix: ~ parent: ~ - kind: @@ -20,10 +20,10 @@ expression: diagnostics - y location: row: 300 - column: 0 + column: 4 end_location: - row: 306 - column: 7 + row: 300 + column: 28 fix: ~ parent: ~ - kind: @@ -34,10 +34,10 @@ expression: diagnostics - z location: row: 324 - column: 4 + column: 8 end_location: - row: 330 - column: 11 + row: 324 + column: 25 fix: ~ parent: ~ - kind: @@ -48,10 +48,10 @@ expression: diagnostics - z location: row: 336 - column: 4 + column: 8 end_location: - row: 343 - column: 11 + row: 336 + column: 38 fix: ~ parent: ~ - kind: @@ -62,10 +62,10 @@ expression: diagnostics - z location: row: 349 - column: 4 + column: 8 end_location: - row: 355 - column: 11 + row: 349 + column: 39 fix: ~ parent: ~ - kind: @@ -75,10 +75,10 @@ expression: diagnostics - b location: row: 361 - column: 4 + column: 8 end_location: - row: 367 - column: 11 + row: 361 + column: 30 fix: ~ parent: ~ - kind: @@ -87,10 +87,10 @@ expression: diagnostics - y location: row: 389 - column: 0 + column: 4 end_location: - row: 398 - column: 7 + row: 389 + column: 27 fix: ~ parent: ~ - kind: @@ -101,10 +101,10 @@ expression: diagnostics - z location: row: 425 - column: 4 + column: 8 end_location: - row: 434 - column: 11 + row: 425 + column: 25 fix: ~ parent: ~ - kind: @@ -115,10 +115,10 @@ expression: diagnostics - z location: row: 440 - column: 4 + column: 8 end_location: - row: 453 - column: 11 + row: 440 + column: 38 fix: ~ parent: ~ - kind: @@ -128,10 +128,10 @@ expression: diagnostics - z location: row: 459 - column: 4 + column: 8 end_location: - row: 469 - column: 11 + row: 459 + column: 39 fix: ~ parent: ~ - kind: @@ -140,10 +140,10 @@ expression: diagnostics - y location: row: 489 - column: 4 + column: 8 end_location: - row: 497 - column: 11 + row: 489 + column: 29 fix: ~ parent: ~ diff --git a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__d417_google.snap b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__d417_google.snap index a058d3a4c9..421e8a1bc6 100644 --- a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__d417_google.snap +++ b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__d417_google.snap @@ -9,10 +9,10 @@ expression: diagnostics - z location: row: 1 - column: 0 + column: 4 end_location: - row: 11 - column: 12 + row: 1 + column: 5 fix: ~ parent: ~ - kind: @@ -22,10 +22,10 @@ expression: diagnostics - z location: row: 14 - column: 0 + column: 4 end_location: - row: 24 - column: 12 + row: 14 + column: 5 fix: ~ parent: ~ - kind: @@ -35,10 +35,10 @@ expression: diagnostics - z location: row: 27 - column: 0 + column: 4 end_location: - row: 36 - column: 12 + row: 27 + column: 5 fix: ~ parent: ~ - kind: @@ -48,10 +48,10 @@ expression: diagnostics - z location: row: 39 - column: 0 + column: 4 end_location: - row: 49 - column: 12 + row: 39 + column: 5 fix: ~ parent: ~ - kind: @@ -60,10 +60,10 @@ expression: diagnostics - y location: row: 52 - column: 0 + column: 4 end_location: - row: 62 - column: 12 + row: 52 + column: 5 fix: ~ parent: ~ - kind: @@ -72,10 +72,10 @@ expression: diagnostics - y location: row: 65 - column: 0 + column: 4 end_location: - row: 74 - column: 12 + row: 65 + column: 5 fix: ~ parent: ~ - kind: @@ -84,10 +84,10 @@ expression: diagnostics - y location: row: 77 - column: 0 + column: 4 end_location: - row: 84 - column: 12 + row: 77 + column: 5 fix: ~ parent: ~ - kind: @@ -96,10 +96,10 @@ expression: diagnostics - x location: row: 98 - column: 0 + column: 4 end_location: - row: 105 - column: 12 + row: 98 + column: 5 fix: ~ parent: ~ - kind: @@ -108,10 +108,10 @@ expression: diagnostics - "*args" location: row: 108 - column: 0 + column: 4 end_location: - row: 115 - column: 12 + row: 108 + column: 5 fix: ~ parent: ~ diff --git a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__d417_unspecified.snap b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__d417_unspecified.snap index debf34c31c..c0e686b9a7 100644 --- a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__d417_unspecified.snap +++ b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__d417_unspecified.snap @@ -9,10 +9,10 @@ expression: diagnostics - z location: row: 27 - column: 0 + column: 4 end_location: - row: 36 - column: 12 + row: 27 + column: 5 fix: ~ parent: ~ - kind: @@ -21,10 +21,10 @@ expression: diagnostics - y location: row: 65 - column: 0 + column: 4 end_location: - row: 74 - column: 12 + row: 65 + column: 5 fix: ~ parent: ~ - kind: @@ -33,10 +33,10 @@ expression: diagnostics - y location: row: 77 - column: 0 + column: 4 end_location: - row: 84 - column: 12 + row: 77 + column: 5 fix: ~ parent: ~ - kind: @@ -45,10 +45,10 @@ expression: diagnostics - x location: row: 98 - column: 0 + column: 4 end_location: - row: 105 - column: 12 + row: 98 + column: 5 fix: ~ parent: ~ - kind: @@ -57,10 +57,10 @@ expression: diagnostics - "*args" location: row: 108 - column: 0 + column: 4 end_location: - row: 115 - column: 12 + row: 108 + column: 5 fix: ~ parent: ~ diff --git a/crates/ruff/src/rules/pylint/rules/property_with_parameters.rs b/crates/ruff/src/rules/pylint/rules/property_with_parameters.rs index 8030c833ba..5f94572fa8 100644 --- a/crates/ruff/src/rules/pylint/rules/property_with_parameters.rs +++ b/crates/ruff/src/rules/pylint/rules/property_with_parameters.rs @@ -1,7 +1,8 @@ -use ruff_macros::{define_violation, derive_message_formats}; use rustpython_parser::ast::{Arguments, Expr, ExprKind, Stmt}; -use crate::ast::types::Range; +use ruff_macros::{define_violation, derive_message_formats}; + +use crate::ast::helpers::identifier_range; use crate::checkers::ast::Checker; use crate::registry::Diagnostic; use crate::violation::Violation; @@ -15,6 +16,7 @@ impl Violation for PropertyWithParameters { format!("Cannot have defined parameters for properties") } } + /// PLR0206 pub fn property_with_parameters( checker: &mut Checker, @@ -39,7 +41,7 @@ pub fn property_with_parameters( { checker.diagnostics.push(Diagnostic::new( PropertyWithParameters, - Range::from_located(stmt), + identifier_range(stmt, checker.locator), )); } } diff --git a/crates/ruff/src/rules/pylint/rules/too_many_arguments.rs b/crates/ruff/src/rules/pylint/rules/too_many_arguments.rs index cf6e5fd31c..0ff44358cd 100644 --- a/crates/ruff/src/rules/pylint/rules/too_many_arguments.rs +++ b/crates/ruff/src/rules/pylint/rules/too_many_arguments.rs @@ -1,7 +1,8 @@ -use ruff_macros::{define_violation, derive_message_formats}; use rustpython_parser::ast::{Arguments, Stmt}; -use crate::ast::types::Range; +use ruff_macros::{define_violation, derive_message_formats}; + +use crate::ast::helpers::identifier_range; use crate::checkers::ast::Checker; use crate::registry::Diagnostic; use crate::violation::Violation; @@ -34,7 +35,7 @@ pub fn too_many_arguments(checker: &mut Checker, args: &Arguments, stmt: &Stmt) c_args: num_args, max_args: checker.settings.pylint.max_args, }, - Range::from_located(stmt), + identifier_range(stmt, checker.locator), )); } } diff --git a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR0206_property_with_parameters.py.snap b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR0206_property_with_parameters.py.snap index 996e3d1695..08dbe29f64 100644 --- a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR0206_property_with_parameters.py.snap +++ b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR0206_property_with_parameters.py.snap @@ -1,35 +1,35 @@ --- -source: src/rules/pylint/mod.rs +source: crates/ruff/src/rules/pylint/mod.rs expression: diagnostics --- - kind: PropertyWithParameters: ~ location: row: 7 - column: 4 + column: 8 end_location: - row: 8 - column: 29 + row: 7 + column: 17 fix: ~ parent: ~ - kind: PropertyWithParameters: ~ location: row: 11 - column: 4 + column: 8 end_location: - row: 12 - column: 29 + row: 11 + column: 30 fix: ~ parent: ~ - kind: PropertyWithParameters: ~ location: row: 15 - column: 4 + column: 8 end_location: - row: 16 - column: 29 + row: 15 + column: 33 fix: ~ parent: ~ diff --git a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR0913_too_many_arguments.py.snap b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR0913_too_many_arguments.py.snap index 1016c33571..0605f098e3 100644 --- a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR0913_too_many_arguments.py.snap +++ b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR0913_too_many_arguments.py.snap @@ -1,5 +1,5 @@ --- -source: src/rules/pylint/mod.rs +source: crates/ruff/src/rules/pylint/mod.rs expression: diagnostics --- - kind: @@ -8,10 +8,10 @@ expression: diagnostics max_args: 5 location: row: 1 - column: 0 + column: 4 end_location: - row: 2 - column: 8 + row: 1 + column: 5 fix: ~ parent: ~ - kind: @@ -20,10 +20,10 @@ expression: diagnostics max_args: 5 location: row: 17 - column: 0 + column: 4 end_location: - row: 18 - column: 8 + row: 17 + column: 5 fix: ~ parent: ~ - kind: @@ -32,10 +32,10 @@ expression: diagnostics max_args: 5 location: row: 33 - column: 0 + column: 4 end_location: - row: 34 - column: 8 + row: 33 + column: 5 fix: ~ parent: ~ diff --git a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__max_args.snap b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__max_args.snap index 590f04c548..e679f5ce35 100644 --- a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__max_args.snap +++ b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__max_args.snap @@ -1,5 +1,5 @@ --- -source: src/rules/pylint/mod.rs +source: crates/ruff/src/rules/pylint/mod.rs expression: diagnostics --- - kind: @@ -8,10 +8,10 @@ expression: diagnostics max_args: 4 location: row: 3 - column: 0 + column: 4 end_location: - row: 4 - column: 8 + row: 3 + column: 5 fix: ~ parent: ~ - kind: @@ -20,10 +20,10 @@ expression: diagnostics max_args: 4 location: row: 9 - column: 0 + column: 4 end_location: - row: 10 - column: 8 + row: 9 + column: 5 fix: ~ parent: ~ diff --git a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__max_args_with_dummy_variables.snap b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__max_args_with_dummy_variables.snap index b8d5a2c2aa..69474d8791 100644 --- a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__max_args_with_dummy_variables.snap +++ b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__max_args_with_dummy_variables.snap @@ -1,5 +1,5 @@ --- -source: src/rules/pylint/mod.rs +source: crates/ruff/src/rules/pylint/mod.rs expression: diagnostics --- - kind: @@ -8,10 +8,10 @@ expression: diagnostics max_args: 5 location: row: 9 - column: 0 + column: 4 end_location: - row: 10 - column: 8 + row: 9 + column: 5 fix: ~ parent: ~