Ignore magic comparisons to bytes by default (#2365)

This commit is contained in:
Charlie Marsh 2023-01-30 16:31:48 -05:00 committed by GitHub
parent ea0274d22c
commit 4589daa0bd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 5 additions and 16 deletions

View file

@ -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>`

View file

@ -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

View file

@ -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,
}
}

View file

@ -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: ~