diff --git a/crates/ruff_linter/src/checkers/ast/analyze/expression.rs b/crates/ruff_linter/src/checkers/ast/analyze/expression.rs index 5536a58a54..d21dc3ccb1 100644 --- a/crates/ruff_linter/src/checkers/ast/analyze/expression.rs +++ b/crates/ruff_linter/src/checkers/ast/analyze/expression.rs @@ -850,9 +850,9 @@ pub(crate) fn expression(expr: &Expr, checker: &mut Checker) { if checker.enabled(Rule::PytestFailWithoutMessage) { flake8_pytest_style::rules::fail_call(checker, call); } - if checker.enabled(Rule::PairwiseOverZipped) { + if checker.enabled(Rule::ZipInsteadOfPairwise) { if checker.settings.target_version >= PythonVersion::Py310 { - ruff::rules::pairwise_over_zipped(checker, func, args); + ruff::rules::zip_instead_of_pairwise(checker, func, args); } } if checker.any_enabled(&[ diff --git a/crates/ruff_linter/src/codes.rs b/crates/ruff_linter/src/codes.rs index 08cbbc174f..2116c89dd9 100644 --- a/crates/ruff_linter/src/codes.rs +++ b/crates/ruff_linter/src/codes.rs @@ -918,7 +918,7 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<(RuleGroup, Rule)> { (Ruff, "003") => (RuleGroup::Stable, rules::ruff::rules::AmbiguousUnicodeCharacterComment), (Ruff, "005") => (RuleGroup::Stable, rules::ruff::rules::CollectionLiteralConcatenation), (Ruff, "006") => (RuleGroup::Stable, rules::ruff::rules::AsyncioDanglingTask), - (Ruff, "007") => (RuleGroup::Stable, rules::ruff::rules::PairwiseOverZipped), + (Ruff, "007") => (RuleGroup::Stable, rules::ruff::rules::ZipInsteadOfPairwise), (Ruff, "008") => (RuleGroup::Stable, rules::ruff::rules::MutableDataclassDefault), (Ruff, "009") => (RuleGroup::Stable, rules::ruff::rules::FunctionCallInDataclassDefaultArgument), (Ruff, "010") => (RuleGroup::Stable, rules::ruff::rules::ExplicitFStringTypeConversion), diff --git a/crates/ruff_linter/src/rules/ruff/mod.rs b/crates/ruff_linter/src/rules/ruff/mod.rs index c9708eb848..bc78b0bda5 100644 --- a/crates/ruff_linter/src/rules/ruff/mod.rs +++ b/crates/ruff_linter/src/rules/ruff/mod.rs @@ -32,7 +32,7 @@ mod tests { #[test_case(Rule::ImplicitOptional, Path::new("RUF013_3.py"))] #[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::ZipInsteadOfPairwise, Path::new("RUF007.py"))] #[test_case( Rule::UnnecessaryIterableAllocationForFirstElement, Path::new("RUF015.py") diff --git a/crates/ruff_linter/src/rules/ruff/rules/mod.rs b/crates/ruff_linter/src/rules/ruff/rules/mod.rs index 399aa8584a..ee615a48d0 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/mod.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/mod.rs @@ -15,7 +15,6 @@ pub(crate) use mutable_class_default::*; pub(crate) use mutable_dataclass_default::*; pub(crate) use mutable_fromkeys_value::*; pub(crate) use never_union::*; -pub(crate) use pairwise_over_zipped::*; pub(crate) use parenthesize_logical_operators::*; pub(crate) use quadratic_list_summation::*; pub(crate) use redirected_noqa::*; @@ -29,6 +28,7 @@ pub(crate) use unnecessary_iterable_allocation_for_first_element::*; pub(crate) use unnecessary_key_check::*; pub(crate) use unused_async::*; pub(crate) use unused_noqa::*; +pub(crate) use zip_instead_of_pairwise::*; mod ambiguous_unicode_character; mod assert_with_print_message; @@ -49,7 +49,6 @@ mod mutable_class_default; mod mutable_dataclass_default; mod mutable_fromkeys_value; mod never_union; -mod pairwise_over_zipped; mod parenthesize_logical_operators; mod quadratic_list_summation; mod redirected_noqa; @@ -65,6 +64,7 @@ mod unnecessary_iterable_allocation_for_first_element; mod unnecessary_key_check; mod unused_async; mod unused_noqa; +mod zip_instead_of_pairwise; #[derive(Clone, Copy)] pub(crate) enum Context { diff --git a/crates/ruff_linter/src/rules/ruff/rules/pairwise_over_zipped.rs b/crates/ruff_linter/src/rules/ruff/rules/zip_instead_of_pairwise.rs similarity index 94% rename from crates/ruff_linter/src/rules/ruff/rules/pairwise_over_zipped.rs rename to crates/ruff_linter/src/rules/ruff/rules/zip_instead_of_pairwise.rs index 03f9ef95f2..b2f696ecad 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/pairwise_over_zipped.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/zip_instead_of_pairwise.rs @@ -32,9 +32,9 @@ use crate::checkers::ast::Checker; /// ## References /// - [Python documentation: `itertools.pairwise`](https://docs.python.org/3/library/itertools.html#itertools.pairwise) #[violation] -pub struct PairwiseOverZipped; +pub struct ZipInsteadOfPairwise; -impl Violation for PairwiseOverZipped { +impl Violation for ZipInsteadOfPairwise { #[derive_message_formats] fn message(&self) -> String { format!("Prefer `itertools.pairwise()` over `zip()` when iterating over successive pairs") @@ -95,7 +95,7 @@ fn match_slice_info(expr: &Expr) -> Option { } /// RUF007 -pub(crate) fn pairwise_over_zipped(checker: &mut Checker, func: &Expr, args: &[Expr]) { +pub(crate) fn zip_instead_of_pairwise(checker: &mut Checker, func: &Expr, args: &[Expr]) { // Require exactly two positional arguments. let [first, second] = args else { return; @@ -141,5 +141,5 @@ pub(crate) fn pairwise_over_zipped(checker: &mut Checker, func: &Expr, args: &[E checker .diagnostics - .push(Diagnostic::new(PairwiseOverZipped, func.range())); + .push(Diagnostic::new(ZipInsteadOfPairwise, func.range())); }