Use identifier_range for a few more rules (#3254)

This commit is contained in:
Charlie Marsh 2023-02-27 13:23:33 -05:00 committed by GitHub
parent d2a6ed7be6
commit c65585e14a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 117 additions and 113 deletions

View file

@ -5,6 +5,7 @@ use ruff_macros::{define_violation, derive_message_formats};
use rustc_hash::FxHashSet; use rustc_hash::FxHashSet;
use rustpython_parser::ast::StmtKind; use rustpython_parser::ast::StmtKind;
use crate::ast::helpers::identifier_range;
use crate::ast::types::Range; use crate::ast::types::Range;
use crate::ast::whitespace::LinesWithTrailingNewline; use crate::ast::whitespace::LinesWithTrailingNewline;
use crate::ast::{cast, whitespace}; 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(); let names = missing_arg_names.into_iter().sorted().collect();
checker.diagnostics.push(Diagnostic::new( checker.diagnostics.push(Diagnostic::new(
UndocumentedParam { names }, UndocumentedParam { names },
Range::from_located(parent), identifier_range(parent, checker.locator),
)); ));
} }
} }

View file

@ -8,10 +8,10 @@ expression: diagnostics
- y - y
location: location:
row: 283 row: 283
column: 4 column: 8
end_location: end_location:
row: 293 row: 283
column: 16 column: 11
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
@ -20,10 +20,10 @@ expression: diagnostics
- y - y
location: location:
row: 300 row: 300
column: 0 column: 4
end_location: end_location:
row: 306 row: 300
column: 7 column: 28
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
@ -34,10 +34,10 @@ expression: diagnostics
- z - z
location: location:
row: 324 row: 324
column: 4 column: 8
end_location: end_location:
row: 330 row: 324
column: 11 column: 25
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
@ -48,10 +48,10 @@ expression: diagnostics
- z - z
location: location:
row: 336 row: 336
column: 4 column: 8
end_location: end_location:
row: 343 row: 336
column: 11 column: 38
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
@ -62,10 +62,10 @@ expression: diagnostics
- z - z
location: location:
row: 349 row: 349
column: 4 column: 8
end_location: end_location:
row: 355 row: 349
column: 11 column: 39
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
@ -75,10 +75,10 @@ expression: diagnostics
- b - b
location: location:
row: 361 row: 361
column: 4 column: 8
end_location: end_location:
row: 367 row: 361
column: 11 column: 30
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
@ -87,10 +87,10 @@ expression: diagnostics
- y - y
location: location:
row: 389 row: 389
column: 0 column: 4
end_location: end_location:
row: 398 row: 389
column: 7 column: 27
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
@ -101,10 +101,10 @@ expression: diagnostics
- z - z
location: location:
row: 425 row: 425
column: 4 column: 8
end_location: end_location:
row: 434 row: 425
column: 11 column: 25
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
@ -115,10 +115,10 @@ expression: diagnostics
- z - z
location: location:
row: 440 row: 440
column: 4 column: 8
end_location: end_location:
row: 453 row: 440
column: 11 column: 38
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
@ -128,10 +128,10 @@ expression: diagnostics
- z - z
location: location:
row: 459 row: 459
column: 4 column: 8
end_location: end_location:
row: 469 row: 459
column: 11 column: 39
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
@ -140,10 +140,10 @@ expression: diagnostics
- y - y
location: location:
row: 489 row: 489
column: 4 column: 8
end_location: end_location:
row: 497 row: 489
column: 11 column: 29
fix: ~ fix: ~
parent: ~ parent: ~

View file

@ -9,10 +9,10 @@ expression: diagnostics
- z - z
location: location:
row: 1 row: 1
column: 0 column: 4
end_location: end_location:
row: 11 row: 1
column: 12 column: 5
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
@ -22,10 +22,10 @@ expression: diagnostics
- z - z
location: location:
row: 14 row: 14
column: 0 column: 4
end_location: end_location:
row: 24 row: 14
column: 12 column: 5
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
@ -35,10 +35,10 @@ expression: diagnostics
- z - z
location: location:
row: 27 row: 27
column: 0 column: 4
end_location: end_location:
row: 36 row: 27
column: 12 column: 5
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
@ -48,10 +48,10 @@ expression: diagnostics
- z - z
location: location:
row: 39 row: 39
column: 0 column: 4
end_location: end_location:
row: 49 row: 39
column: 12 column: 5
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
@ -60,10 +60,10 @@ expression: diagnostics
- y - y
location: location:
row: 52 row: 52
column: 0 column: 4
end_location: end_location:
row: 62 row: 52
column: 12 column: 5
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
@ -72,10 +72,10 @@ expression: diagnostics
- y - y
location: location:
row: 65 row: 65
column: 0 column: 4
end_location: end_location:
row: 74 row: 65
column: 12 column: 5
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
@ -84,10 +84,10 @@ expression: diagnostics
- y - y
location: location:
row: 77 row: 77
column: 0 column: 4
end_location: end_location:
row: 84 row: 77
column: 12 column: 5
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
@ -96,10 +96,10 @@ expression: diagnostics
- x - x
location: location:
row: 98 row: 98
column: 0 column: 4
end_location: end_location:
row: 105 row: 98
column: 12 column: 5
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
@ -108,10 +108,10 @@ expression: diagnostics
- "*args" - "*args"
location: location:
row: 108 row: 108
column: 0 column: 4
end_location: end_location:
row: 115 row: 108
column: 12 column: 5
fix: ~ fix: ~
parent: ~ parent: ~

View file

@ -9,10 +9,10 @@ expression: diagnostics
- z - z
location: location:
row: 27 row: 27
column: 0 column: 4
end_location: end_location:
row: 36 row: 27
column: 12 column: 5
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
@ -21,10 +21,10 @@ expression: diagnostics
- y - y
location: location:
row: 65 row: 65
column: 0 column: 4
end_location: end_location:
row: 74 row: 65
column: 12 column: 5
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
@ -33,10 +33,10 @@ expression: diagnostics
- y - y
location: location:
row: 77 row: 77
column: 0 column: 4
end_location: end_location:
row: 84 row: 77
column: 12 column: 5
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
@ -45,10 +45,10 @@ expression: diagnostics
- x - x
location: location:
row: 98 row: 98
column: 0 column: 4
end_location: end_location:
row: 105 row: 98
column: 12 column: 5
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
@ -57,10 +57,10 @@ expression: diagnostics
- "*args" - "*args"
location: location:
row: 108 row: 108
column: 0 column: 4
end_location: end_location:
row: 115 row: 108
column: 12 column: 5
fix: ~ fix: ~
parent: ~ parent: ~

View file

@ -1,7 +1,8 @@
use ruff_macros::{define_violation, derive_message_formats};
use rustpython_parser::ast::{Arguments, Expr, ExprKind, Stmt}; 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::checkers::ast::Checker;
use crate::registry::Diagnostic; use crate::registry::Diagnostic;
use crate::violation::Violation; use crate::violation::Violation;
@ -15,6 +16,7 @@ impl Violation for PropertyWithParameters {
format!("Cannot have defined parameters for properties") format!("Cannot have defined parameters for properties")
} }
} }
/// PLR0206 /// PLR0206
pub fn property_with_parameters( pub fn property_with_parameters(
checker: &mut Checker, checker: &mut Checker,
@ -39,7 +41,7 @@ pub fn property_with_parameters(
{ {
checker.diagnostics.push(Diagnostic::new( checker.diagnostics.push(Diagnostic::new(
PropertyWithParameters, PropertyWithParameters,
Range::from_located(stmt), identifier_range(stmt, checker.locator),
)); ));
} }
} }

View file

@ -1,7 +1,8 @@
use ruff_macros::{define_violation, derive_message_formats};
use rustpython_parser::ast::{Arguments, Stmt}; 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::checkers::ast::Checker;
use crate::registry::Diagnostic; use crate::registry::Diagnostic;
use crate::violation::Violation; use crate::violation::Violation;
@ -34,7 +35,7 @@ pub fn too_many_arguments(checker: &mut Checker, args: &Arguments, stmt: &Stmt)
c_args: num_args, c_args: num_args,
max_args: checker.settings.pylint.max_args, max_args: checker.settings.pylint.max_args,
}, },
Range::from_located(stmt), identifier_range(stmt, checker.locator),
)); ));
} }
} }

View file

@ -1,35 +1,35 @@
--- ---
source: src/rules/pylint/mod.rs source: crates/ruff/src/rules/pylint/mod.rs
expression: diagnostics expression: diagnostics
--- ---
- kind: - kind:
PropertyWithParameters: ~ PropertyWithParameters: ~
location: location:
row: 7 row: 7
column: 4 column: 8
end_location: end_location:
row: 8 row: 7
column: 29 column: 17
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
PropertyWithParameters: ~ PropertyWithParameters: ~
location: location:
row: 11 row: 11
column: 4 column: 8
end_location: end_location:
row: 12 row: 11
column: 29 column: 30
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
PropertyWithParameters: ~ PropertyWithParameters: ~
location: location:
row: 15 row: 15
column: 4 column: 8
end_location: end_location:
row: 16 row: 15
column: 29 column: 33
fix: ~ fix: ~
parent: ~ parent: ~

View file

@ -1,5 +1,5 @@
--- ---
source: src/rules/pylint/mod.rs source: crates/ruff/src/rules/pylint/mod.rs
expression: diagnostics expression: diagnostics
--- ---
- kind: - kind:
@ -8,10 +8,10 @@ expression: diagnostics
max_args: 5 max_args: 5
location: location:
row: 1 row: 1
column: 0 column: 4
end_location: end_location:
row: 2 row: 1
column: 8 column: 5
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
@ -20,10 +20,10 @@ expression: diagnostics
max_args: 5 max_args: 5
location: location:
row: 17 row: 17
column: 0 column: 4
end_location: end_location:
row: 18 row: 17
column: 8 column: 5
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
@ -32,10 +32,10 @@ expression: diagnostics
max_args: 5 max_args: 5
location: location:
row: 33 row: 33
column: 0 column: 4
end_location: end_location:
row: 34 row: 33
column: 8 column: 5
fix: ~ fix: ~
parent: ~ parent: ~

View file

@ -1,5 +1,5 @@
--- ---
source: src/rules/pylint/mod.rs source: crates/ruff/src/rules/pylint/mod.rs
expression: diagnostics expression: diagnostics
--- ---
- kind: - kind:
@ -8,10 +8,10 @@ expression: diagnostics
max_args: 4 max_args: 4
location: location:
row: 3 row: 3
column: 0 column: 4
end_location: end_location:
row: 4 row: 3
column: 8 column: 5
fix: ~ fix: ~
parent: ~ parent: ~
- kind: - kind:
@ -20,10 +20,10 @@ expression: diagnostics
max_args: 4 max_args: 4
location: location:
row: 9 row: 9
column: 0 column: 4
end_location: end_location:
row: 10 row: 9
column: 8 column: 5
fix: ~ fix: ~
parent: ~ parent: ~

View file

@ -1,5 +1,5 @@
--- ---
source: src/rules/pylint/mod.rs source: crates/ruff/src/rules/pylint/mod.rs
expression: diagnostics expression: diagnostics
--- ---
- kind: - kind:
@ -8,10 +8,10 @@ expression: diagnostics
max_args: 5 max_args: 5
location: location:
row: 9 row: 9
column: 0 column: 4
end_location: end_location:
row: 10 row: 9
column: 8 column: 5
fix: ~ fix: ~
parent: ~ parent: ~