Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Ruff v0.5] Stabilise 15 pylint rules #12051

Merged
merged 4 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions crates/ruff_linter/src/codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,14 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<(RuleGroup, Rule)> {
(Pylint, "C0414") => (RuleGroup::Stable, rules::pylint::rules::UselessImportAlias),
(Pylint, "C0415") => (RuleGroup::Preview, rules::pylint::rules::ImportOutsideTopLevel),
(Pylint, "C1901") => (RuleGroup::Preview, rules::pylint::rules::CompareToEmptyString),
(Pylint, "C2401") => (RuleGroup::Preview, rules::pylint::rules::NonAsciiName),
(Pylint, "C2403") => (RuleGroup::Preview, rules::pylint::rules::NonAsciiImportName),
(Pylint, "C2401") => (RuleGroup::Stable, rules::pylint::rules::NonAsciiName),
(Pylint, "C2403") => (RuleGroup::Stable, rules::pylint::rules::NonAsciiImportName),
(Pylint, "C2701") => (RuleGroup::Preview, rules::pylint::rules::ImportPrivateName),
(Pylint, "C2801") => (RuleGroup::Preview, rules::pylint::rules::UnnecessaryDunderCall),
(Pylint, "C3002") => (RuleGroup::Stable, rules::pylint::rules::UnnecessaryDirectLambdaCall),
(Pylint, "E0100") => (RuleGroup::Stable, rules::pylint::rules::YieldInInit),
(Pylint, "E0101") => (RuleGroup::Stable, rules::pylint::rules::ReturnInInit),
(Pylint, "E0115") => (RuleGroup::Preview, rules::pylint::rules::NonlocalAndGlobal),
(Pylint, "E0115") => (RuleGroup::Stable, rules::pylint::rules::NonlocalAndGlobal),
(Pylint, "E0116") => (RuleGroup::Stable, rules::pylint::rules::ContinueInFinally),
(Pylint, "E0117") => (RuleGroup::Stable, rules::pylint::rules::NonlocalWithoutBinding),
(Pylint, "E0118") => (RuleGroup::Stable, rules::pylint::rules::LoadBeforeGlobalDeclaration),
Expand All @@ -213,9 +213,9 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<(RuleGroup, Rule)> {
(Pylint, "E0309") => (RuleGroup::Preview, rules::pylint::rules::InvalidHashReturnType),
(Pylint, "E0604") => (RuleGroup::Stable, rules::pylint::rules::InvalidAllObject),
(Pylint, "E0605") => (RuleGroup::Stable, rules::pylint::rules::InvalidAllFormat),
(Pylint, "E0643") => (RuleGroup::Preview, rules::pylint::rules::PotentialIndexError),
(Pylint, "E0704") => (RuleGroup::Preview, rules::pylint::rules::MisplacedBareRaise),
(Pylint, "E1132") => (RuleGroup::Preview, rules::pylint::rules::RepeatedKeywordArgument),
(Pylint, "E0643") => (RuleGroup::Stable, rules::pylint::rules::PotentialIndexError),
(Pylint, "E0704") => (RuleGroup::Stable, rules::pylint::rules::MisplacedBareRaise),
(Pylint, "E1132") => (RuleGroup::Stable, rules::pylint::rules::RepeatedKeywordArgument),
(Pylint, "E1141") => (RuleGroup::Preview, rules::pylint::rules::DictIterMissingItems),
(Pylint, "E1142") => (RuleGroup::Stable, rules::pylint::rules::AwaitOutsideAsync),
(Pylint, "E1205") => (RuleGroup::Stable, rules::pylint::rules::LoggingTooManyArgs),
Expand Down Expand Up @@ -250,16 +250,16 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<(RuleGroup, Rule)> {
(Pylint, "R0917") => (RuleGroup::Preview, rules::pylint::rules::TooManyPositional),
(Pylint, "R1701") => (RuleGroup::Removed, rules::pylint::rules::RepeatedIsinstanceCalls),
(Pylint, "R1702") => (RuleGroup::Preview, rules::pylint::rules::TooManyNestedBlocks),
(Pylint, "R1704") => (RuleGroup::Preview, rules::pylint::rules::RedefinedArgumentFromLocal),
(Pylint, "R1704") => (RuleGroup::Stable, rules::pylint::rules::RedefinedArgumentFromLocal),
(Pylint, "R1706") => (RuleGroup::Removed, rules::pylint::rules::AndOrTernary),
(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, "R1733") => (RuleGroup::Preview, rules::pylint::rules::UnnecessaryDictIndexLookup),
(Pylint, "R1736") => (RuleGroup::Preview, rules::pylint::rules::UnnecessaryListIndexLookup),
(Pylint, "R1736") => (RuleGroup::Stable, rules::pylint::rules::UnnecessaryListIndexLookup),
(Pylint, "R2004") => (RuleGroup::Stable, rules::pylint::rules::MagicValueComparison),
(Pylint, "R2044") => (RuleGroup::Preview, rules::pylint::rules::EmptyComment),
(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, "R6201") => (RuleGroup::Preview, rules::pylint::rules::LiteralMembership),
Expand All @@ -268,25 +268,25 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<(RuleGroup, Rule)> {
(Pylint, "W0177") => (RuleGroup::Preview, rules::pylint::rules::NanComparison),
(Pylint, "W0120") => (RuleGroup::Stable, rules::pylint::rules::UselessElseOnLoop),
(Pylint, "W0127") => (RuleGroup::Stable, rules::pylint::rules::SelfAssigningVariable),
(Pylint, "W0128") => (RuleGroup::Preview, rules::pylint::rules::RedeclaredAssignedName),
(Pylint, "W0128") => (RuleGroup::Stable, rules::pylint::rules::RedeclaredAssignedName),
(Pylint, "W0129") => (RuleGroup::Stable, rules::pylint::rules::AssertOnStringLiteral),
(Pylint, "W0131") => (RuleGroup::Stable, rules::pylint::rules::NamedExprWithoutContext),
(Pylint, "W0133") => (RuleGroup::Preview, rules::pylint::rules::UselessExceptionStatement),
(Pylint, "W0133") => (RuleGroup::Stable, rules::pylint::rules::UselessExceptionStatement),
(Pylint, "W0211") => (RuleGroup::Preview, rules::pylint::rules::BadStaticmethodArgument),
(Pylint, "W0245") => (RuleGroup::Preview, rules::pylint::rules::SuperWithoutBrackets),
(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::Preview, rules::pylint::rules::GlobalAtModuleLevel),
(Pylint, "W0604") => (RuleGroup::Stable, rules::pylint::rules::GlobalAtModuleLevel),
(Pylint, "W0642") => (RuleGroup::Preview, rules::pylint::rules::SelfOrClsAssignment),
(Pylint, "W0711") => (RuleGroup::Stable, rules::pylint::rules::BinaryOpException),
(Pylint, "W1501") => (RuleGroup::Preview, rules::pylint::rules::BadOpenMode),
(Pylint, "W1501") => (RuleGroup::Stable, rules::pylint::rules::BadOpenMode),
(Pylint, "W1508") => (RuleGroup::Stable, rules::pylint::rules::InvalidEnvvarDefault),
(Pylint, "W1509") => (RuleGroup::Stable, rules::pylint::rules::SubprocessPopenPreexecFn),
(Pylint, "W1510") => (RuleGroup::Stable, rules::pylint::rules::SubprocessRunWithoutCheck),
(Pylint, "W1514") => (RuleGroup::Preview, rules::pylint::rules::UnspecifiedEncoding),
(Pylint, "W1641") => (RuleGroup::Preview, rules::pylint::rules::EqWithoutHash),
(Pylint, "W2101") => (RuleGroup::Preview, rules::pylint::rules::UselessWithLock),
(Pylint, "W2101") => (RuleGroup::Stable, rules::pylint::rules::UselessWithLock),
(Pylint, "W2901") => (RuleGroup::Stable, rules::pylint::rules::RedefinedLoopName),
(Pylint, "W3201") => (RuleGroup::Preview, rules::pylint::rules::BadDunderMethodName),
(Pylint, "W3301") => (RuleGroup::Stable, rules::pylint::rules::NestedMinMax),
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff_linter/src/rules/pylint/rules/bad_open_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub(crate) fn bad_open_mode(checker: &mut Checker, call: &ast::ExprCall) {
return;
};

let Some(ast::ExprStringLiteral { value, .. }) = mode.as_string_literal_expr() else {
let ast::Expr::StringLiteral(ast::ExprStringLiteral { value, .. }) = mode else {
return;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub struct LiteralMembership;
impl AlwaysFixableViolation for LiteralMembership {
#[derive_message_formats]
fn message(&self) -> String {
format!("Use a `set` literal when testing for membership")
format!("Use a set literal when testing for membership")
}

fn fix_title(&self) -> String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,20 @@ impl Violation for NonAsciiImportName {
let Self { name, kind } = self;
match kind {
Kind::Aliased => {
format!(
"Module alias `{name}` contains a non-ASCII character, use an ASCII-only alias"
)
format!("Module alias `{name}` contains a non-ASCII character")
}
Kind::Unaliased => {
format!(
"Module name `{name}` contains a non-ASCII character, use an ASCII-only alias"
)
format!("Module name `{name}` contains a non-ASCII character")
}
}
}

fn fix_title(&self) -> Option<String> {
Some("Use an ASCII-only alias".to_string())
}
}

#[derive(Debug, PartialEq, Eq)]
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
enum Kind {
/// The import uses a non-ASCII alias (e.g., `import foo as bár`).
Aliased,
Expand Down
8 changes: 6 additions & 2 deletions crates/ruff_linter/src/rules/pylint/rules/non_ascii_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ impl Violation for NonAsciiName {
#[derive_message_formats]
fn message(&self) -> String {
let Self { name, kind } = self;
format!("{kind} name `{name}` contains a non-ASCII character, consider renaming it")
format!("{kind} name `{name}` contains a non-ASCII character")
}

fn fix_title(&self) -> Option<String> {
Some("Rename the variable using ASCII characters".to_string())
}
}

Expand Down Expand Up @@ -82,7 +86,7 @@ pub(crate) fn non_ascii_name(binding: &Binding, locator: &Locator) -> Option<Dia
))
}

#[derive(Debug, PartialEq, Eq)]
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
enum Kind {
Annotation,
Argument,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub struct PotentialIndexError;
impl Violation for PotentialIndexError {
#[derive_message_formats]
fn message(&self) -> String {
format!("Potential IndexError")
format!("Expression is likely to raise `IndexError`")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ use ruff_text_size::Ranged;
use crate::checkers::ast::Checker;

/// ## What it does
/// Checks for `super` calls without parentheses.
/// Detects attempts to use `super` without parentheses.
///
/// ## Why is this bad?
/// When `super` is used without parentheses, it is not an actual call, and
/// thus has no effect.
/// The [`super()` callable](https://docs.python.org/3/library/functions.html#super)
/// can be used inside method definitions to create a proxy object that
/// delegates attribute access to a superclass of the current class. Attempting
/// to access attributes on the `super` object itself, however, instead of the
/// object returned by a call to `super()`, will raise `AttributeError`.
///
/// ## Example
/// ```python
Expand All @@ -25,7 +28,7 @@ use crate::checkers::ast::Checker;
/// class Dog(Animal):
/// @staticmethod
/// def speak():
/// original_speak = super.speak()
/// original_speak = super.speak() # ERROR: `super.speak()`
/// return f"{original_speak} But as a dog, it barks!"
/// ```
///
Expand All @@ -40,7 +43,7 @@ use crate::checkers::ast::Checker;
/// class Dog(Animal):
/// @staticmethod
/// def speak():
/// original_speak = super().speak()
/// original_speak = super().speak() # Correct: `super().speak()`
/// return f"{original_speak} But as a dog, it barks!"
/// ```
#[violation]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ pub struct UnnecessaryListIndexLookup;
impl AlwaysFixableViolation for UnnecessaryListIndexLookup {
#[derive_message_formats]
fn message(&self) -> String {
format!("Unnecessary lookup of list item by index")
format!("List index lookup in `enumerate()` loop")
}

fn fix_title(&self) -> String {
format!("Use existing variable")
format!("Use the loop variable directly")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use ruff_text_size::Ranged;
use crate::checkers::ast::Checker;

/// ## What it does
/// Checks for direct uses of lock objects in `with` statements.
/// Checks for lock objects that are created and immediately discarded in
/// `with` statements.
///
/// ## Why is this bad?
/// Creating a lock (via `threading.Lock` or similar) in a `with` statement
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
---
source: crates/ruff_linter/src/rules/pylint/mod.rs
---
non_ascii_name.py:1:1: PLC2401 Variable name `ápple_count` contains a non-ASCII character, consider renaming it
non_ascii_name.py:1:1: PLC2401 Variable name `ápple_count` contains a non-ASCII character
|
1 | ápple_count: int = 1 # C2401
| ^^^^^^^^^^^ PLC2401
2 | ápple_count += 2 # C2401
3 | ápple_count = 3 # C2401
|
= help: Rename the variable using ASCII characters

non_ascii_name.py:2:1: PLC2401 Variable name `ápple_count` contains a non-ASCII character, consider renaming it
non_ascii_name.py:2:1: PLC2401 Variable name `ápple_count` contains a non-ASCII character
|
1 | ápple_count: int = 1 # C2401
2 | ápple_count += 2 # C2401
| ^^^^^^^^^^^ PLC2401
3 | ápple_count = 3 # C2401
|
= help: Rename the variable using ASCII characters

non_ascii_name.py:3:1: PLC2401 Variable name `ápple_count` contains a non-ASCII character, consider renaming it
non_ascii_name.py:3:1: PLC2401 Variable name `ápple_count` contains a non-ASCII character
|
1 | ápple_count: int = 1 # C2401
2 | ápple_count += 2 # C2401
Expand All @@ -26,47 +28,53 @@ non_ascii_name.py:3:1: PLC2401 Variable name `ápple_count` contains a non-ASCII
4 |
5 |pple_count for ápple_count in y)
|
= help: Rename the variable using ASCII characters

non_ascii_name.py:5:18: PLC2401 Variable name `ápple_count` contains a non-ASCII character, consider renaming it
non_ascii_name.py:5:18: PLC2401 Variable name `ápple_count` contains a non-ASCII character
|
3 | ápple_count = 3 # C2401
4 |
5 |pple_count for ápple_count in y)
| ^^^^^^^^^^^ PLC2401
|
= help: Rename the variable using ASCII characters

non_ascii_name.py:8:10: PLC2401 Argument name `ápple_count` contains a non-ASCII character, consider renaming it
non_ascii_name.py:8:10: PLC2401 Argument name `ápple_count` contains a non-ASCII character
|
8 | def funcpple_count):
| ^^^^^^^^^^^ PLC2401
9 | global ápple_count
10 | nonlocal ápple_count
|
= help: Rename the variable using ASCII characters

non_ascii_name.py:9:12: PLC2401 Global name `ápple_count` contains a non-ASCII character, consider renaming it
non_ascii_name.py:9:12: PLC2401 Global name `ápple_count` contains a non-ASCII character
|
8 | def funcpple_count):
9 | global ápple_count
| ^^^^^^^^^^^ PLC2401
10 | nonlocal ápple_count
|
= help: Rename the variable using ASCII characters

non_ascii_name.py:13:5: PLC2401 Function name `ápple_count` contains a non-ASCII character, consider renaming it
non_ascii_name.py:13:5: PLC2401 Function name `ápple_count` contains a non-ASCII character
|
13 | def ápple_count():
| ^^^^^^^^^^^ PLC2401
14 | pass
|
= help: Rename the variable using ASCII characters

non_ascii_name.py:18:10: PLC2401 Variable name `ápple_count` contains a non-ASCII character, consider renaming it
non_ascii_name.py:18:10: PLC2401 Variable name `ápple_count` contains a non-ASCII character
|
17 | match ápple_count:
18 | case ápple_count:
| ^^^^^^^^^^^ PLC2401
19 | pass
|
= help: Rename the variable using ASCII characters

non_ascii_name.py:21:1: PLC2401 Annotation name `ápple_count` contains a non-ASCII character, consider renaming it
non_ascii_name.py:21:1: PLC2401 Annotation name `ápple_count` contains a non-ASCII character
|
19 | pass
20 |
Expand All @@ -75,5 +83,4 @@ non_ascii_name.py:21:1: PLC2401 Annotation name `ápple_count` contains a non-AS
22 |
23 | try:
|


= help: Rename the variable using ASCII characters
Original file line number Diff line number Diff line change
@@ -1,38 +1,40 @@
---
source: crates/ruff_linter/src/rules/pylint/mod.rs
---
non_ascii_module_import.py:1:29: PLC2403 Module alias `łos` contains a non-ASCII character, use an ASCII-only alias
non_ascii_module_import.py:1:29: PLC2403 Module alias `łos` contains a non-ASCII character
|
1 | from os.path import join as łos # Error
| ^^^ PLC2403
2 | from os.path import join as los # OK
|
= help: Use an ASCII-only alias

non_ascii_module_import.py:4:24: PLC2403 Module alias `łos` contains a non-ASCII character, use an ASCII-only alias
non_ascii_module_import.py:4:24: PLC2403 Module alias `łos` contains a non-ASCII character
|
2 | from os.path import join as los # OK
3 |
4 | import os.path.join as łos # Error
| ^^^ PLC2403
5 | import os.path.join as los # OK
|
= help: Use an ASCII-only alias

non_ascii_module_import.py:7:8: PLC2403 Module name `os.path.łos` contains a non-ASCII character, use an ASCII-only alias
non_ascii_module_import.py:7:8: PLC2403 Module name `os.path.łos` contains a non-ASCII character
|
5 | import os.path.join as los # OK
6 |
7 | import os.pathos # Error (recommend an ASCII alias)
| ^^^^^^^^^^^ PLC2403
8 | import os.path.los # OK
|
= help: Use an ASCII-only alias

non_ascii_module_import.py:10:21: PLC2403 Module name `łos` contains a non-ASCII character, use an ASCII-only alias
non_ascii_module_import.py:10:21: PLC2403 Module name `łos` contains a non-ASCII character
|
8 | import os.path.los # OK
9 |
10 | from os.path import łos # Error (recommend an ASCII alias)
| ^^^ PLC2403
11 | from os.path import los # OK
|


= help: Use an ASCII-only alias
Loading
Loading