Skip to content

Commit

Permalink
Align names, fix rebase errors, rerun tests with new message
Browse files Browse the repository at this point in the history
  • Loading branch information
qdegraaf committed Jul 27, 2023
1 parent aa6b1ca commit 634c6d2
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 54 deletions.
2 changes: 1 addition & 1 deletion crates/ruff/src/codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<(RuleGroup, Rule)> {
(Perflint, "203") => (RuleGroup::Unspecified, rules::perflint::rules::TryExceptInLoop),
(Perflint, "401") => (RuleGroup::Unspecified, rules::perflint::rules::ManualListComprehension),
(Perflint, "402") => (RuleGroup::Unspecified, rules::perflint::rules::ManualListCopy),
(Perflint, "403") => (RuleGroup::Unspecified, rules::perflint::rules::ManualDictCreation),
(Perflint, "403") => (RuleGroup::Unspecified, rules::perflint::rules::ManualDictComprehension),

// flake8-fixme
(Flake8Fixme, "001") => (RuleGroup::Unspecified, rules::flake8_fixme::rules::LineContainsFixme),
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff/src/rules/perflint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ mod tests {
#[test_case(Rule::TryExceptInLoop, Path::new("PERF203.py"))]
#[test_case(Rule::ManualListComprehension, Path::new("PERF401.py"))]
#[test_case(Rule::ManualListCopy, Path::new("PERF402.py"))]
#[test_case(Rule::SlowDictCreation, Path::new("PERF403.py"))]
#[test_case(Rule::ManualDictComprehension, Path::new("PERF403.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
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ use crate::checkers::ast::Checker;
/// result = {x: y for x, y in pairs if y % 2}
/// ```
#[violation]
pub struct ManualDictCreation;
pub struct ManualDictComprehension;

impl Violation for ManualDictCreation {
impl Violation for ManualDictComprehension {
#[derive_message_formats]
fn message(&self) -> String {
format!("Use a dictionary comprehension instead of a for-loop")
Expand Down Expand Up @@ -107,6 +107,6 @@ fn check_for_slow_dict_creation(checker: &mut Checker, names: &[&str], stmt: &St
if names.contains(&value.as_str()) && names.contains(&key.as_str()) {
checker
.diagnostics
.push(Diagnostic::new(ManualDictCreation, *range));
.push(Diagnostic::new(ManualDictComprehension, *range));
}
}
4 changes: 0 additions & 4 deletions crates/ruff/src/rules/perflint/rules/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,10 @@ pub(crate) use manual_list_comprehension::*;
pub(crate) use manual_list_copy::*;
pub(crate) use try_except_in_loop::*;
pub(crate) use unnecessary_list_cast::*;
pub(crate) use slow_dict_creation::{slow_dict_creation, SlowDictCreation};
pub(crate) use unnecessary_list_cast::*;

mod incorrect_dict_iterator;
mod manual_dict_comprehension;
mod manual_list_comprehension;
mod manual_list_copy;
mod try_except_in_loop;
mod unnecessary_list_cast;
mod slow_dict_creation;
mod unnecessary_list_cast;
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
---
source: crates/ruff/src/rules/perflint/mod.rs
---
PERF403.py:5:9: PERF403 Use a dict comprehension to create a (filtered) copy of a dict
PERF403.py:5:9: PERF403 Use a dictionary comprehension instead of a for-loop
|
3 | fruit = ["apple", "pear", "orange"]
4 | for idx, name in enumerate(fruit):
5 | result[idx] = name # PERF403
| ^^^^^^^^^^^^^^^^^^ PERF403
|

PERF403.py:13:13: PERF403 Use a dict comprehension to create a (filtered) copy of a dict
PERF403.py:13:13: PERF403 Use a dictionary comprehension instead of a for-loop
|
11 | for idx, name in enumerate(fruit):
12 | if idx % 2:
13 | result[idx] = name # PERF403
| ^^^^^^^^^^^^^^^^^^ PERF403
|

PERF403.py:21:13: PERF403 Use a dict comprehension to create a (filtered) copy of a dict
PERF403.py:21:13: PERF403 Use a dictionary comprehension instead of a for-loop
|
19 | for idx, name in enumerate(fruit):
20 | if idx % 2:
Expand All @@ -27,7 +27,7 @@ PERF403.py:21:13: PERF403 Use a dict comprehension to create a (filtered) copy o
23 | result[idx] = name
|

PERF403.py:33:13: PERF403 Use a dict comprehension to create a (filtered) copy of a dict
PERF403.py:33:13: PERF403 Use a dictionary comprehension instead of a for-loop
|
31 | for idx, name in enumerate(fruit):
32 | if idx % 2:
Expand Down

This file was deleted.

0 comments on commit 634c6d2

Please sign in to comment.