mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-29 13:25:17 +00:00
Recategorize static-key-dict-comprehension
from RUF011
to B035
(#9428)
## Summary This rule was added to flake8-bugbear. In general, we tend to prefer redirecting to prominent plugins when our own rules are reimplemented (since more projects have `B` activated than `RUF`). ## Test Plan `cargo test` # Conflicts: # crates/ruff_linter/src/rules/ruff/rules/mod.rs
This commit is contained in:
parent
b81fc5ed11
commit
7962bca40a
11 changed files with 29 additions and 28 deletions
|
@ -1446,7 +1446,7 @@ pub(crate) fn expression(expr: &Expr, checker: &mut Checker) {
|
|||
}
|
||||
}
|
||||
if checker.enabled(Rule::StaticKeyDictComprehension) {
|
||||
ruff::rules::static_key_dict_comprehension(checker, dict_comp);
|
||||
flake8_bugbear::rules::static_key_dict_comprehension(checker, dict_comp);
|
||||
}
|
||||
}
|
||||
Expr::GeneratorExp(
|
||||
|
|
|
@ -351,6 +351,7 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<(RuleGroup, Rule)> {
|
|||
(Flake8Bugbear, "032") => (RuleGroup::Stable, rules::flake8_bugbear::rules::UnintentionalTypeAnnotation),
|
||||
(Flake8Bugbear, "033") => (RuleGroup::Stable, rules::flake8_bugbear::rules::DuplicateValue),
|
||||
(Flake8Bugbear, "034") => (RuleGroup::Stable, rules::flake8_bugbear::rules::ReSubPositionalArgs),
|
||||
(Flake8Bugbear, "035") => (RuleGroup::Stable, rules::flake8_bugbear::rules::StaticKeyDictComprehension),
|
||||
(Flake8Bugbear, "904") => (RuleGroup::Stable, rules::flake8_bugbear::rules::RaiseWithoutFromInsideExcept),
|
||||
(Flake8Bugbear, "905") => (RuleGroup::Stable, rules::flake8_bugbear::rules::ZipWithoutExplicitStrict),
|
||||
|
||||
|
@ -916,7 +917,6 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<(RuleGroup, Rule)> {
|
|||
(Ruff, "008") => (RuleGroup::Stable, rules::ruff::rules::MutableDataclassDefault),
|
||||
(Ruff, "009") => (RuleGroup::Stable, rules::ruff::rules::FunctionCallInDataclassDefaultArgument),
|
||||
(Ruff, "010") => (RuleGroup::Stable, rules::ruff::rules::ExplicitFStringTypeConversion),
|
||||
(Ruff, "011") => (RuleGroup::Stable, rules::ruff::rules::StaticKeyDictComprehension),
|
||||
(Ruff, "012") => (RuleGroup::Stable, rules::ruff::rules::MutableClassDefault),
|
||||
(Ruff, "013") => (RuleGroup::Stable, rules::ruff::rules::ImplicitOptional),
|
||||
(Ruff, "015") => (RuleGroup::Stable, rules::ruff::rules::UnnecessaryIterableAllocationForFirstElement),
|
||||
|
|
|
@ -98,5 +98,6 @@ static REDIRECTS: Lazy<HashMap<&'static str, &'static str>> = Lazy::new(|| {
|
|||
("T002", "FIX002"),
|
||||
("T003", "FIX003"),
|
||||
("T004", "FIX004"),
|
||||
("RUF011", "B035"),
|
||||
])
|
||||
});
|
||||
|
|
|
@ -34,7 +34,6 @@ mod tests {
|
|||
#[test_case(Rule::GetAttrWithConstant, Path::new("B009_B010.py"))]
|
||||
#[test_case(Rule::JumpStatementInFinally, Path::new("B012.py"))]
|
||||
#[test_case(Rule::LoopVariableOverridesIterator, Path::new("B020.py"))]
|
||||
#[test_case(Rule::MutableArgumentDefault, Path::new("B006_B008.py"))]
|
||||
#[test_case(Rule::MutableArgumentDefault, Path::new("B006_1.py"))]
|
||||
#[test_case(Rule::MutableArgumentDefault, Path::new("B006_2.py"))]
|
||||
#[test_case(Rule::MutableArgumentDefault, Path::new("B006_3.py"))]
|
||||
|
@ -42,6 +41,7 @@ mod tests {
|
|||
#[test_case(Rule::MutableArgumentDefault, Path::new("B006_5.py"))]
|
||||
#[test_case(Rule::MutableArgumentDefault, Path::new("B006_6.py"))]
|
||||
#[test_case(Rule::MutableArgumentDefault, Path::new("B006_7.py"))]
|
||||
#[test_case(Rule::MutableArgumentDefault, Path::new("B006_B008.py"))]
|
||||
#[test_case(Rule::NoExplicitStacklevel, Path::new("B028.py"))]
|
||||
#[test_case(Rule::RaiseLiteral, Path::new("B016.py"))]
|
||||
#[test_case(Rule::RaiseWithoutFromInsideExcept, Path::new("B904.py"))]
|
||||
|
@ -50,16 +50,17 @@ mod tests {
|
|||
#[test_case(Rule::ReuseOfGroupbyGenerator, Path::new("B031.py"))]
|
||||
#[test_case(Rule::SetAttrWithConstant, Path::new("B009_B010.py"))]
|
||||
#[test_case(Rule::StarArgUnpackingAfterKeywordArg, Path::new("B026.py"))]
|
||||
#[test_case(Rule::StaticKeyDictComprehension, Path::new("B035.py"))]
|
||||
#[test_case(Rule::StripWithMultiCharacters, Path::new("B005.py"))]
|
||||
#[test_case(Rule::UnaryPrefixIncrementDecrement, Path::new("B002.py"))]
|
||||
#[test_case(Rule::UnintentionalTypeAnnotation, Path::new("B032.py"))]
|
||||
#[test_case(Rule::UnreliableCallableCheck, Path::new("B004.py"))]
|
||||
#[test_case(Rule::UnusedLoopControlVariable, Path::new("B007.py"))]
|
||||
#[test_case(Rule::UselessComparison, Path::new("B015.py"))]
|
||||
#[test_case(Rule::UselessComparison, Path::new("B015.ipynb"))]
|
||||
#[test_case(Rule::UselessComparison, Path::new("B015.py"))]
|
||||
#[test_case(Rule::UselessContextlibSuppress, Path::new("B022.py"))]
|
||||
#[test_case(Rule::UselessExpression, Path::new("B018.py"))]
|
||||
#[test_case(Rule::UselessExpression, Path::new("B018.ipynb"))]
|
||||
#[test_case(Rule::UselessExpression, Path::new("B018.py"))]
|
||||
fn rules(rule_code: Rule, path: &Path) -> Result<()> {
|
||||
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
|
||||
let diagnostics = test_path(
|
||||
|
|
|
@ -22,6 +22,7 @@ pub(crate) use redundant_tuple_in_exception_handler::*;
|
|||
pub(crate) use reuse_of_groupby_generator::*;
|
||||
pub(crate) use setattr_with_constant::*;
|
||||
pub(crate) use star_arg_unpacking_after_keyword_arg::*;
|
||||
pub(crate) use static_key_dict_comprehension::*;
|
||||
pub(crate) use strip_with_multi_characters::*;
|
||||
pub(crate) use unary_prefix_increment_decrement::*;
|
||||
pub(crate) use unintentional_type_annotation::*;
|
||||
|
@ -56,6 +57,7 @@ mod redundant_tuple_in_exception_handler;
|
|||
mod reuse_of_groupby_generator;
|
||||
mod setattr_with_constant;
|
||||
mod star_arg_unpacking_after_keyword_arg;
|
||||
mod static_key_dict_comprehension;
|
||||
mod strip_with_multi_characters;
|
||||
mod unary_prefix_increment_decrement;
|
||||
mod unintentional_type_annotation;
|
||||
|
|
|
@ -1,90 +1,90 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/rules/ruff/mod.rs
|
||||
source: crates/ruff_linter/src/rules/flake8_bugbear/mod.rs
|
||||
---
|
||||
RUF011.py:17:2: RUF011 Dictionary comprehension uses static key: `"key"`
|
||||
B035.py:17:2: B035 Dictionary comprehension uses static key: `"key"`
|
||||
|
|
||||
16 | # Errors
|
||||
17 | {"key": value.upper() for value in data}
|
||||
| ^^^^^ RUF011
|
||||
| ^^^^^ B035
|
||||
18 | {True: value.upper() for value in data}
|
||||
19 | {0: value.upper() for value in data}
|
||||
|
|
||||
|
||||
RUF011.py:18:2: RUF011 Dictionary comprehension uses static key: `True`
|
||||
B035.py:18:2: B035 Dictionary comprehension uses static key: `True`
|
||||
|
|
||||
16 | # Errors
|
||||
17 | {"key": value.upper() for value in data}
|
||||
18 | {True: value.upper() for value in data}
|
||||
| ^^^^ RUF011
|
||||
| ^^^^ B035
|
||||
19 | {0: value.upper() for value in data}
|
||||
20 | {(1, "a"): value.upper() for value in data} # Constant tuple
|
||||
|
|
||||
|
||||
RUF011.py:19:2: RUF011 Dictionary comprehension uses static key: `0`
|
||||
B035.py:19:2: B035 Dictionary comprehension uses static key: `0`
|
||||
|
|
||||
17 | {"key": value.upper() for value in data}
|
||||
18 | {True: value.upper() for value in data}
|
||||
19 | {0: value.upper() for value in data}
|
||||
| ^ RUF011
|
||||
| ^ B035
|
||||
20 | {(1, "a"): value.upper() for value in data} # Constant tuple
|
||||
21 | {constant: value.upper() for value in data}
|
||||
|
|
||||
|
||||
RUF011.py:20:2: RUF011 Dictionary comprehension uses static key: `(1, "a")`
|
||||
B035.py:20:2: B035 Dictionary comprehension uses static key: `(1, "a")`
|
||||
|
|
||||
18 | {True: value.upper() for value in data}
|
||||
19 | {0: value.upper() for value in data}
|
||||
20 | {(1, "a"): value.upper() for value in data} # Constant tuple
|
||||
| ^^^^^^^^ RUF011
|
||||
| ^^^^^^^^ B035
|
||||
21 | {constant: value.upper() for value in data}
|
||||
22 | {constant + constant: value.upper() for value in data}
|
||||
|
|
||||
|
||||
RUF011.py:21:2: RUF011 Dictionary comprehension uses static key: `constant`
|
||||
B035.py:21:2: B035 Dictionary comprehension uses static key: `constant`
|
||||
|
|
||||
19 | {0: value.upper() for value in data}
|
||||
20 | {(1, "a"): value.upper() for value in data} # Constant tuple
|
||||
21 | {constant: value.upper() for value in data}
|
||||
| ^^^^^^^^ RUF011
|
||||
| ^^^^^^^^ B035
|
||||
22 | {constant + constant: value.upper() for value in data}
|
||||
23 | {constant.attribute: value.upper() for value in data}
|
||||
|
|
||||
|
||||
RUF011.py:22:2: RUF011 Dictionary comprehension uses static key: `constant + constant`
|
||||
B035.py:22:2: B035 Dictionary comprehension uses static key: `constant + constant`
|
||||
|
|
||||
20 | {(1, "a"): value.upper() for value in data} # Constant tuple
|
||||
21 | {constant: value.upper() for value in data}
|
||||
22 | {constant + constant: value.upper() for value in data}
|
||||
| ^^^^^^^^^^^^^^^^^^^ RUF011
|
||||
| ^^^^^^^^^^^^^^^^^^^ B035
|
||||
23 | {constant.attribute: value.upper() for value in data}
|
||||
24 | {constant[0]: value.upper() for value in data}
|
||||
|
|
||||
|
||||
RUF011.py:23:2: RUF011 Dictionary comprehension uses static key: `constant.attribute`
|
||||
B035.py:23:2: B035 Dictionary comprehension uses static key: `constant.attribute`
|
||||
|
|
||||
21 | {constant: value.upper() for value in data}
|
||||
22 | {constant + constant: value.upper() for value in data}
|
||||
23 | {constant.attribute: value.upper() for value in data}
|
||||
| ^^^^^^^^^^^^^^^^^^ RUF011
|
||||
| ^^^^^^^^^^^^^^^^^^ B035
|
||||
24 | {constant[0]: value.upper() for value in data}
|
||||
25 | {tokens: token for token in tokens}
|
||||
|
|
||||
|
||||
RUF011.py:24:2: RUF011 Dictionary comprehension uses static key: `constant[0]`
|
||||
B035.py:24:2: B035 Dictionary comprehension uses static key: `constant[0]`
|
||||
|
|
||||
22 | {constant + constant: value.upper() for value in data}
|
||||
23 | {constant.attribute: value.upper() for value in data}
|
||||
24 | {constant[0]: value.upper() for value in data}
|
||||
| ^^^^^^^^^^^ RUF011
|
||||
| ^^^^^^^^^^^ B035
|
||||
25 | {tokens: token for token in tokens}
|
||||
|
|
||||
|
||||
RUF011.py:25:2: RUF011 Dictionary comprehension uses static key: `tokens`
|
||||
B035.py:25:2: B035 Dictionary comprehension uses static key: `tokens`
|
||||
|
|
||||
23 | {constant.attribute: value.upper() for value in data}
|
||||
24 | {constant[0]: value.upper() for value in data}
|
||||
25 | {tokens: token for token in tokens}
|
||||
| ^^^^^^ RUF011
|
||||
| ^^^^^^ B035
|
||||
|
|
||||
|
||||
|
|
@ -30,7 +30,6 @@ mod tests {
|
|||
#[test_case(Rule::MutableClassDefault, Path::new("RUF012.py"))]
|
||||
#[test_case(Rule::MutableDataclassDefault, Path::new("RUF008.py"))]
|
||||
#[test_case(Rule::PairwiseOverZipped, Path::new("RUF007.py"))]
|
||||
#[test_case(Rule::StaticKeyDictComprehension, Path::new("RUF011.py"))]
|
||||
#[test_case(
|
||||
Rule::UnnecessaryIterableAllocationForFirstElement,
|
||||
Path::new("RUF015.py")
|
||||
|
|
|
@ -17,7 +17,6 @@ pub(crate) use parenthesize_logical_operators::*;
|
|||
pub(crate) use quadratic_list_summation::*;
|
||||
pub(crate) use sort_dunder_all::*;
|
||||
pub(crate) use sort_dunder_slots::*;
|
||||
pub(crate) use static_key_dict_comprehension::*;
|
||||
#[cfg(feature = "test-rules")]
|
||||
pub(crate) use test_rules::*;
|
||||
pub(crate) use unnecessary_dict_comprehension_for_iterable::*;
|
||||
|
@ -46,7 +45,6 @@ mod parenthesize_logical_operators;
|
|||
mod sequence_sorting;
|
||||
mod sort_dunder_all;
|
||||
mod sort_dunder_slots;
|
||||
mod static_key_dict_comprehension;
|
||||
#[cfg(feature = "test-rules")]
|
||||
pub(crate) mod test_rules;
|
||||
mod unnecessary_dict_comprehension_for_iterable;
|
||||
|
|
2
ruff.schema.json
generated
2
ruff.schema.json
generated
|
@ -2665,6 +2665,7 @@
|
|||
"B032",
|
||||
"B033",
|
||||
"B034",
|
||||
"B035",
|
||||
"B9",
|
||||
"B90",
|
||||
"B904",
|
||||
|
@ -3506,7 +3507,6 @@
|
|||
"RUF009",
|
||||
"RUF01",
|
||||
"RUF010",
|
||||
"RUF011",
|
||||
"RUF012",
|
||||
"RUF013",
|
||||
"RUF015",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue