Skip to content

Commit

Permalink
Rename rule
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Nov 19, 2023
1 parent 35ef030 commit 529d459
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 19 deletions.
4 changes: 2 additions & 2 deletions crates/ruff_linter/src/checkers/ast/analyze/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -776,8 +776,8 @@ pub(crate) fn expression(expr: &Expr, checker: &mut Checker) {
if checker.enabled(Rule::NestedMinMax) {
pylint::rules::nested_min_max(checker, expr, func, args, keywords);
}
if checker.enabled(Rule::RepeatedKeywords) {
pylint::rules::repeated_keywords(checker, call);
if checker.enabled(Rule::RepeatedKeywordArgument) {
pylint::rules::repeated_keyword_argument(checker, call);
}
if checker.enabled(Rule::PytestPatchWithLambda) {
if let Some(diagnostic) = flake8_pytest_style::rules::patch_with_lambda(call) {
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff_linter/src/codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<(RuleGroup, Rule)> {
(Pylint, "E0604") => (RuleGroup::Stable, rules::pylint::rules::InvalidAllObject),
(Pylint, "E0605") => (RuleGroup::Stable, rules::pylint::rules::InvalidAllFormat),
(Pylint, "E0704") => (RuleGroup::Preview, rules::pylint::rules::MisplacedBareRaise),
(Pylint, "E1132") => (RuleGroup::Preview, rules::pylint::rules::RepeatedKeywords),
(Pylint, "E1132") => (RuleGroup::Preview, rules::pylint::rules::RepeatedKeywordArgument),
(Pylint, "E1142") => (RuleGroup::Stable, rules::pylint::rules::AwaitOutsideAsync),
(Pylint, "E1205") => (RuleGroup::Stable, rules::pylint::rules::LoggingTooManyArgs),
(Pylint, "E1206") => (RuleGroup::Stable, rules::pylint::rules::LoggingTooFewArgs),
Expand Down
5 changes: 4 additions & 1 deletion crates/ruff_linter/src/rules/pylint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,10 @@ mod tests {
#[test_case(Rule::UnnecessaryLambda, Path::new("unnecessary_lambda.py"))]
#[test_case(Rule::NonAsciiImportName, Path::new("non_ascii_module_import.py"))]
#[test_case(Rule::NonAsciiName, Path::new("non_ascii_name.py"))]
#[test_case(Rule::RepeatedKeywords, Path::new("repeated_keywords.py"))]
#[test_case(
Rule::RepeatedKeywordArgument,
Path::new("repeated_keyword_argument.py")
)]
fn rules(rule_code: Rule, path: &Path) -> Result<()> {
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
let diagnostics = test_path(
Expand Down
4 changes: 2 additions & 2 deletions crates/ruff_linter/src/rules/pylint/rules/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub(crate) use redefined_argument_from_local::*;
pub(crate) use redefined_loop_name::*;
pub(crate) use repeated_equality_comparison::*;
pub(crate) use repeated_isinstance_calls::*;
pub(crate) use repeated_keywords::*;
pub(crate) use repeated_keyword_argument::*;
pub(crate) use return_in_init::*;
pub(crate) use self_assigning_variable::*;
pub(crate) use single_string_slots::*;
Expand Down Expand Up @@ -117,7 +117,7 @@ mod redefined_argument_from_local;
mod redefined_loop_name;
mod repeated_equality_comparison;
mod repeated_isinstance_calls;
mod repeated_keywords;
mod repeated_keyword_argument;
mod return_in_init;
mod self_assigning_variable;
mod single_string_slots;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@ use crate::checkers::ast::Checker;
/// ## References
/// - [Python documentation: Argument](https://docs.python.org/3/glossary.html#term-argument)
#[violation]
pub struct RepeatedKeywords {
pub struct RepeatedKeywordArgument {
duplicate_keyword: String,
}

impl Violation for RepeatedKeywords {
impl Violation for RepeatedKeywordArgument {
#[derive_message_formats]
fn message(&self) -> String {
let Self { duplicate_keyword } = self;
format!("Repeated keyword argument: `{duplicate_keyword}`")
}
}

pub(crate) fn repeated_keywords(checker: &mut Checker, call: &ExprCall) {
pub(crate) fn repeated_keyword_argument(checker: &mut Checker, call: &ExprCall) {
let ExprCall {
arguments: Arguments { keywords, .. },
..
Expand All @@ -50,7 +50,7 @@ pub(crate) fn repeated_keywords(checker: &mut Checker, call: &ExprCall) {
// Ex) `func(a=1, a=2)`
if !seen.insert(id.as_str()) {
checker.diagnostics.push(Diagnostic::new(
RepeatedKeywords {
RepeatedKeywordArgument {
duplicate_keyword: id.to_string(),
},
keyword.range(),
Expand All @@ -62,7 +62,7 @@ pub(crate) fn repeated_keywords(checker: &mut Checker, call: &ExprCall) {
if let Expr::StringLiteral(ExprStringLiteral { value, .. }) = key {
if !seen.insert(value) {
checker.diagnostics.push(Diagnostic::new(
RepeatedKeywords {
RepeatedKeywordArgument {
duplicate_keyword: value.to_string(),
},
key.range(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
source: crates/ruff_linter/src/rules/pylint/mod.rs
---
repeated_keywords.py:16:21: PLE1132 Repeated keyword argument: `c`
repeated_keyword_argument.py:16:21: PLE1132 Repeated keyword argument: `c`
|
15 | # Invalid
16 | func(a=11, c=31, **{"c": 41})
Expand All @@ -10,7 +10,7 @@ repeated_keywords.py:16:21: PLE1132 Repeated keyword argument: `c`
18 | func(a=11, b=21, c=31, **{"b": 22, "c": 41, "a": 51})
|

repeated_keywords.py:17:21: PLE1132 Repeated keyword argument: `c`
repeated_keyword_argument.py:17:21: PLE1132 Repeated keyword argument: `c`
|
15 | # Invalid
16 | func(a=11, c=31, **{"c": 41})
Expand All @@ -20,7 +20,7 @@ repeated_keywords.py:17:21: PLE1132 Repeated keyword argument: `c`
19 | func(a=11, b=21, **{"c": 31}, **{"c": 32})
|

repeated_keywords.py:17:30: PLE1132 Repeated keyword argument: `a`
repeated_keyword_argument.py:17:30: PLE1132 Repeated keyword argument: `a`
|
15 | # Invalid
16 | func(a=11, c=31, **{"c": 41})
Expand All @@ -30,7 +30,7 @@ repeated_keywords.py:17:30: PLE1132 Repeated keyword argument: `a`
19 | func(a=11, b=21, **{"c": 31}, **{"c": 32})
|

repeated_keywords.py:18:27: PLE1132 Repeated keyword argument: `b`
repeated_keyword_argument.py:18:27: PLE1132 Repeated keyword argument: `b`
|
16 | func(a=11, c=31, **{"c": 41})
17 | func(a=11, c=31, **{"c": 41, "a": 51})
Expand All @@ -40,7 +40,7 @@ repeated_keywords.py:18:27: PLE1132 Repeated keyword argument: `b`
20 | func(a=11, b=21, **{"c": 31, "c": 32})
|

repeated_keywords.py:18:36: PLE1132 Repeated keyword argument: `c`
repeated_keyword_argument.py:18:36: PLE1132 Repeated keyword argument: `c`
|
16 | func(a=11, c=31, **{"c": 41})
17 | func(a=11, c=31, **{"c": 41, "a": 51})
Expand All @@ -50,7 +50,7 @@ repeated_keywords.py:18:36: PLE1132 Repeated keyword argument: `c`
20 | func(a=11, b=21, **{"c": 31, "c": 32})
|

repeated_keywords.py:18:45: PLE1132 Repeated keyword argument: `a`
repeated_keyword_argument.py:18:45: PLE1132 Repeated keyword argument: `a`
|
16 | func(a=11, c=31, **{"c": 41})
17 | func(a=11, c=31, **{"c": 41, "a": 51})
Expand All @@ -60,7 +60,7 @@ repeated_keywords.py:18:45: PLE1132 Repeated keyword argument: `a`
20 | func(a=11, b=21, **{"c": 31, "c": 32})
|

repeated_keywords.py:19:34: PLE1132 Repeated keyword argument: `c`
repeated_keyword_argument.py:19:34: PLE1132 Repeated keyword argument: `c`
|
17 | func(a=11, c=31, **{"c": 41, "a": 51})
18 | func(a=11, b=21, c=31, **{"b": 22, "c": 41, "a": 51})
Expand All @@ -69,7 +69,7 @@ repeated_keywords.py:19:34: PLE1132 Repeated keyword argument: `c`
20 | func(a=11, b=21, **{"c": 31, "c": 32})
|

repeated_keywords.py:20:30: PLE1132 Repeated keyword argument: `c`
repeated_keyword_argument.py:20:30: PLE1132 Repeated keyword argument: `c`
|
18 | func(a=11, b=21, c=31, **{"b": 22, "c": 41, "a": 51})
19 | func(a=11, b=21, **{"c": 31}, **{"c": 32})
Expand Down

0 comments on commit 529d459

Please sign in to comment.