From b54bc7ce97e4ffac3bf35885413cf159ab607faf Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Tue, 13 Aug 2024 13:00:39 +0100 Subject: [PATCH] [Ruff 0.6] Stabilise 10 pylint rules --- crates/ruff_linter/src/codes.rs | 20 +++++++++---------- .../src/rules/pylint/rules/if_stmt_min_max.rs | 4 ++-- .../pylint/rules/invalid_bytes_return.rs | 2 +- .../rules/pylint/rules/invalid_hash_return.rs | 5 ++--- .../pylint/rules/invalid_index_return.rs | 3 +-- .../pylint/rules/invalid_length_return.rs | 7 +++---- .../pylint/rules/non_augmented_assignment.rs | 12 +++++------ .../pylint/rules/self_or_cls_assignment.rs | 2 +- 8 files changed, 26 insertions(+), 29 deletions(-) diff --git a/crates/ruff_linter/src/codes.rs b/crates/ruff_linter/src/codes.rs index a3b71b2b440ae9..b325712f276528 100644 --- a/crates/ruff_linter/src/codes.rs +++ b/crates/ruff_linter/src/codes.rs @@ -206,12 +206,12 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<(RuleGroup, Rule)> { (Pylint, "E0237") => (RuleGroup::Stable, rules::pylint::rules::NonSlotAssignment), (Pylint, "E0241") => (RuleGroup::Stable, rules::pylint::rules::DuplicateBases), (Pylint, "E0302") => (RuleGroup::Stable, rules::pylint::rules::UnexpectedSpecialMethodSignature), - (Pylint, "E0303") => (RuleGroup::Preview, rules::pylint::rules::InvalidLengthReturnType), + (Pylint, "E0303") => (RuleGroup::Stable, rules::pylint::rules::InvalidLengthReturnType), (Pylint, "E0304") => (RuleGroup::Preview, rules::pylint::rules::InvalidBoolReturnType), - (Pylint, "E0305") => (RuleGroup::Preview, rules::pylint::rules::InvalidIndexReturnType), + (Pylint, "E0305") => (RuleGroup::Stable, rules::pylint::rules::InvalidIndexReturnType), (Pylint, "E0307") => (RuleGroup::Stable, rules::pylint::rules::InvalidStrReturnType), - (Pylint, "E0308") => (RuleGroup::Preview, rules::pylint::rules::InvalidBytesReturnType), - (Pylint, "E0309") => (RuleGroup::Preview, rules::pylint::rules::InvalidHashReturnType), + (Pylint, "E0308") => (RuleGroup::Stable, rules::pylint::rules::InvalidBytesReturnType), + (Pylint, "E0309") => (RuleGroup::Stable, rules::pylint::rules::InvalidHashReturnType), (Pylint, "E0604") => (RuleGroup::Stable, rules::pylint::rules::InvalidAllObject), (Pylint, "E0605") => (RuleGroup::Stable, rules::pylint::rules::InvalidAllFormat), (Pylint, "E0643") => (RuleGroup::Stable, rules::pylint::rules::PotentialIndexError), @@ -225,8 +225,8 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<(RuleGroup, Rule)> { (Pylint, "E1307") => (RuleGroup::Stable, rules::pylint::rules::BadStringFormatType), (Pylint, "E1310") => (RuleGroup::Stable, rules::pylint::rules::BadStrStripCall), (Pylint, "E1507") => (RuleGroup::Stable, rules::pylint::rules::InvalidEnvvarValue), - (Pylint, "E1519") => (RuleGroup::Preview, rules::pylint::rules::SingledispatchMethod), - (Pylint, "E1520") => (RuleGroup::Preview, rules::pylint::rules::SingledispatchmethodFunction), + (Pylint, "E1519") => (RuleGroup::Stable, rules::pylint::rules::SingledispatchMethod), + (Pylint, "E1520") => (RuleGroup::Stable, rules::pylint::rules::SingledispatchmethodFunction), (Pylint, "E1700") => (RuleGroup::Stable, rules::pylint::rules::YieldFromInAsyncFunction), (Pylint, "E2502") => (RuleGroup::Stable, rules::pylint::rules::BidirectionalUnicode), (Pylint, "E2510") => (RuleGroup::Stable, rules::pylint::rules::InvalidCharacterBackspace), @@ -256,13 +256,13 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<(RuleGroup, Rule)> { (Pylint, "R1711") => (RuleGroup::Stable, rules::pylint::rules::UselessReturn), (Pylint, "R1714") => (RuleGroup::Stable, rules::pylint::rules::RepeatedEqualityComparison), (Pylint, "R1722") => (RuleGroup::Stable, rules::pylint::rules::SysExitAlias), - (Pylint, "R1730") => (RuleGroup::Preview, rules::pylint::rules::IfStmtMinMax), + (Pylint, "R1730") => (RuleGroup::Stable, rules::pylint::rules::IfStmtMinMax), (Pylint, "R1733") => (RuleGroup::Preview, rules::pylint::rules::UnnecessaryDictIndexLookup), (Pylint, "R1736") => (RuleGroup::Stable, rules::pylint::rules::UnnecessaryListIndexLookup), (Pylint, "R2004") => (RuleGroup::Stable, rules::pylint::rules::MagicValueComparison), (Pylint, "R2044") => (RuleGroup::Stable, rules::pylint::rules::EmptyComment), (Pylint, "R5501") => (RuleGroup::Stable, rules::pylint::rules::CollapsibleElseIf), - (Pylint, "R6104") => (RuleGroup::Preview, rules::pylint::rules::NonAugmentedAssignment), + (Pylint, "R6104") => (RuleGroup::Stable, rules::pylint::rules::NonAugmentedAssignment), (Pylint, "R6201") => (RuleGroup::Preview, rules::pylint::rules::LiteralMembership), (Pylint, "R6301") => (RuleGroup::Preview, rules::pylint::rules::NoSelfUse), (Pylint, "W0108") => (RuleGroup::Preview, rules::pylint::rules::UnnecessaryLambda), @@ -273,13 +273,13 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<(RuleGroup, Rule)> { (Pylint, "W0129") => (RuleGroup::Stable, rules::pylint::rules::AssertOnStringLiteral), (Pylint, "W0131") => (RuleGroup::Stable, rules::pylint::rules::NamedExprWithoutContext), (Pylint, "W0133") => (RuleGroup::Stable, rules::pylint::rules::UselessExceptionStatement), - (Pylint, "W0211") => (RuleGroup::Preview, rules::pylint::rules::BadStaticmethodArgument), + (Pylint, "W0211") => (RuleGroup::Stable, rules::pylint::rules::BadStaticmethodArgument), (Pylint, "W0245") => (RuleGroup::Stable, rules::pylint::rules::SuperWithoutBrackets), (Pylint, "W0406") => (RuleGroup::Stable, rules::pylint::rules::ImportSelf), (Pylint, "W0602") => (RuleGroup::Stable, rules::pylint::rules::GlobalVariableNotAssigned), (Pylint, "W0603") => (RuleGroup::Stable, rules::pylint::rules::GlobalStatement), (Pylint, "W0604") => (RuleGroup::Stable, rules::pylint::rules::GlobalAtModuleLevel), - (Pylint, "W0642") => (RuleGroup::Preview, rules::pylint::rules::SelfOrClsAssignment), + (Pylint, "W0642") => (RuleGroup::Stable, rules::pylint::rules::SelfOrClsAssignment), (Pylint, "W0711") => (RuleGroup::Stable, rules::pylint::rules::BinaryOpException), (Pylint, "W1501") => (RuleGroup::Stable, rules::pylint::rules::BadOpenMode), (Pylint, "W1508") => (RuleGroup::Stable, rules::pylint::rules::InvalidEnvvarDefault), diff --git a/crates/ruff_linter/src/rules/pylint/rules/if_stmt_min_max.rs b/crates/ruff_linter/src/rules/pylint/rules/if_stmt_min_max.rs index 9d31d3711b4d5b..f83280dc289121 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/if_stmt_min_max.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/if_stmt_min_max.rs @@ -14,7 +14,7 @@ use crate::fix::snippet::SourceCodeSnippet; /// /// ## Why is this bad? /// An `if` statement that selects the lesser or greater of two sub-expressions -/// can be replaced with a `min()` or `max()` call respectively. When possible, +/// can be replaced with a `min()` or `max()` call respectively. Where possible, /// prefer `min()` and `max()`, as they're more concise and readable than the /// equivalent `if` statements. /// @@ -194,7 +194,7 @@ enum MinMax { } impl MinMax { - fn as_str(self) -> &'static str { + const fn as_str(self) -> &'static str { match self { Self::Min => "min", Self::Max => "max", diff --git a/crates/ruff_linter/src/rules/pylint/rules/invalid_bytes_return.rs b/crates/ruff_linter/src/rules/pylint/rules/invalid_bytes_return.rs index 846c4c86c9e172..8287fbb16f086f 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/invalid_bytes_return.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/invalid_bytes_return.rs @@ -12,7 +12,7 @@ use ruff_text_size::Ranged; use crate::checkers::ast::Checker; /// ## What it does -/// Checks for `__bytes__` implementations that return a type other than `bytes`. +/// Checks for `__bytes__` implementations that return types other than `bytes`. /// /// ## Why is this bad? /// The `__bytes__` method should return a `bytes` object. Returning a different diff --git a/crates/ruff_linter/src/rules/pylint/rules/invalid_hash_return.rs b/crates/ruff_linter/src/rules/pylint/rules/invalid_hash_return.rs index 1a32228c50f9e3..187ec300c5e278 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/invalid_hash_return.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/invalid_hash_return.rs @@ -12,7 +12,7 @@ use ruff_text_size::Ranged; use crate::checkers::ast::Checker; /// ## What it does -/// Checks for `__hash__` implementations that return a value other than an integer. +/// Checks for `__hash__` implementations that return non-integer values. /// /// ## Why is this bad? /// The `__hash__` method should return an integer. Returning a different @@ -20,7 +20,7 @@ use crate::checkers::ast::Checker; /// /// Note: `bool` is a subclass of `int`, so it's technically valid for `__hash__` to /// return `True` or `False`. However, for consistency with other rules, Ruff will -/// still raise when `__hash__` returns a `bool`. +/// still emit a diagnostic when `__hash__` returns a `bool`. /// /// ## Example /// ```python @@ -36,7 +36,6 @@ use crate::checkers::ast::Checker; /// return 2 /// ``` /// -/// /// ## References /// - [Python documentation: The `__hash__` method](https://docs.python.org/3/reference/datamodel.html#object.__hash__) #[violation] diff --git a/crates/ruff_linter/src/rules/pylint/rules/invalid_index_return.rs b/crates/ruff_linter/src/rules/pylint/rules/invalid_index_return.rs index d92ee4a259126b..eea1bafa770dd8 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/invalid_index_return.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/invalid_index_return.rs @@ -12,7 +12,7 @@ use ruff_text_size::Ranged; use crate::checkers::ast::Checker; /// ## What it does -/// Checks for `__index__` implementations that return a value other than an integer. +/// Checks for `__index__` implementations that return non-integer values. /// /// ## Why is this bad? /// The `__index__` method should return an integer. Returning a different @@ -38,7 +38,6 @@ use crate::checkers::ast::Checker; /// return 2 /// ``` /// -/// /// ## References /// - [Python documentation: The `__index__` method](https://docs.python.org/3/reference/datamodel.html#object.__index__) #[violation] diff --git a/crates/ruff_linter/src/rules/pylint/rules/invalid_length_return.rs b/crates/ruff_linter/src/rules/pylint/rules/invalid_length_return.rs index e36984c24aa295..6b8b21f477136d 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/invalid_length_return.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/invalid_length_return.rs @@ -12,8 +12,8 @@ use ruff_text_size::Ranged; use crate::checkers::ast::Checker; /// ## What it does -/// Checks for `__len__` implementations that return values other than a non-negative -/// integer. +/// Checks for `__len__` implementations that return values that are not non-negative +/// integers. /// /// ## Why is this bad? /// The `__len__` method should return a non-negative integer. Returning a different @@ -21,7 +21,7 @@ use crate::checkers::ast::Checker; /// /// Note: `bool` is a subclass of `int`, so it's technically valid for `__len__` to /// return `True` or `False`. However, for consistency with other rules, Ruff will -/// still raise when `__len__` returns a `bool`. +/// still emit a diagnostic when `__len__` returns a `bool`. /// /// ## Example /// ```python @@ -37,7 +37,6 @@ use crate::checkers::ast::Checker; /// return 2 /// ``` /// -/// /// ## References /// - [Python documentation: The `__len__` method](https://docs.python.org/3/reference/datamodel.html#object.__len__) #[violation] diff --git a/crates/ruff_linter/src/rules/pylint/rules/non_augmented_assignment.rs b/crates/ruff_linter/src/rules/pylint/rules/non_augmented_assignment.rs index fa73252872ef77..a0b2ccf3bb0b75 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/non_augmented_assignment.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/non_augmented_assignment.rs @@ -14,12 +14,12 @@ use crate::checkers::ast::Checker; /// statements. /// /// ## Why is this bad? -/// If an assignment statement consists of a binary operation in which one -/// operand is the same as the assignment target, it can be rewritten as an -/// augmented assignment. For example, `x = x + 1` can be rewritten as -/// `x += 1`. +/// If the right-hand side of an assignment statement consists of a binary +/// operation in which one operand is the same as the assignment target, +/// it can be rewritten as an augmented assignment. For example, `x = x + 1 +/// can be rewritten as `x += 1`. /// -/// When performing such an operation, augmented assignments are more concise +/// When performing such an operation, an augmented assignment is more concise /// and idiomatic. /// /// ## Known problems @@ -31,7 +31,7 @@ use crate::checkers::ast::Checker; /// For example, `x = "prefix-" + x` is not equivalent to `x += "prefix-"`, /// while `x = 1 + x` is equivalent to `x += 1`. /// -/// If the type of the left-hand side cannot be inferred trivially, the rule +/// If the type of the left-hand side cannot be trivially inferred, the rule /// will ignore the assignment. /// /// ## Example diff --git a/crates/ruff_linter/src/rules/pylint/rules/self_or_cls_assignment.rs b/crates/ruff_linter/src/rules/pylint/rules/self_or_cls_assignment.rs index 622c1aaee9eceb..8a20ce4a8ecc0d 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/self_or_cls_assignment.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/self_or_cls_assignment.rs @@ -11,7 +11,7 @@ use crate::checkers::ast::Checker; /// Checks for assignment of `self` and `cls` in instance and class methods respectively. /// /// ## Why is this bad? -/// The identifiers `self` and `cls` are conventional in Python for the first argument of instance +/// The identifiers `self` and `cls` are conventional in Python for the first parameter of instance /// methods and class methods, respectively. /// /// ## Example