mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-03 10:22:24 +00:00
Ignore magic comparisons to bytes by default (#2365)
This commit is contained in:
parent
ea0274d22c
commit
4589daa0bd
4 changed files with 5 additions and 16 deletions
|
@ -3778,7 +3778,7 @@ convention = "google"
|
|||
|
||||
Constant types to ignore when used as "magic values" (see: `PLR2004`).
|
||||
|
||||
**Default value**: `["str"]`
|
||||
**Default value**: `["str", "bytes"]`
|
||||
|
||||
**Type**: `Vec<ConstantType>`
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ if input_password == "": # correct
|
|||
if input_password == ADMIN_PASSWORD: # correct
|
||||
pass
|
||||
|
||||
if input_password == "Hunter2": # [magic-value-comparison]
|
||||
if input_password == "Hunter2": # correct
|
||||
pass
|
||||
|
||||
PI = 3.141592653589793238
|
||||
|
@ -62,7 +62,7 @@ if pi_estimation == PI: # correct
|
|||
HELLO_WORLD = b"Hello, World!"
|
||||
user_input = b"Hello, There!"
|
||||
|
||||
if user_input == b"something": # [magic-value-comparison]
|
||||
if user_input == b"something": # correct
|
||||
pass
|
||||
|
||||
if user_input == HELLO_WORLD: # correct
|
||||
|
|
|
@ -45,7 +45,7 @@ impl TryFrom<&Constant> for ConstantType {
|
|||
)]
|
||||
pub struct Options {
|
||||
#[option(
|
||||
default = r#"["str"]"#,
|
||||
default = r#"["str", "bytes"]"#,
|
||||
value_type = "Vec<ConstantType>",
|
||||
example = r#"
|
||||
allow-magic-value-types = ["int"]
|
||||
|
@ -67,7 +67,7 @@ pub struct Settings {
|
|||
impl Default for Settings {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
allow_magic_value_types: vec![ConstantType::Str],
|
||||
allow_magic_value_types: vec![ConstantType::Str, ConstantType::Bytes],
|
||||
max_args: 5,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,15 +35,4 @@ expression: diagnostics
|
|||
column: 40
|
||||
fix: ~
|
||||
parent: ~
|
||||
- kind:
|
||||
MagicValueComparison:
|
||||
value: "b'something'"
|
||||
location:
|
||||
row: 65
|
||||
column: 17
|
||||
end_location:
|
||||
row: 65
|
||||
column: 29
|
||||
fix: ~
|
||||
parent: ~
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue