-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PLR2004
: Accept 0.0 and 1.0 as common magic values (#9964)
## Summary Accept 0.0 and 1.0 as common magic values. This is in line with the pylint behaviour, and I think makes sense conceptually. ## Test Plan Test cases were added to `crates/ruff_linter/resources/test/fixtures/pylint/magic_value_comparison.py`
- Loading branch information
1 parent
5bc0d9c
commit 8fba97f
Showing
4 changed files
with
92 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 31 additions & 13 deletions
44
...rc/rules/pylint/snapshots/ruff_linter__rules__pylint__tests__allow_magic_value_types.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,49 @@ | ||
--- | ||
source: crates/ruff_linter/src/rules/pylint/mod.rs | ||
--- | ||
magic_value_comparison.py:59:22: PLR2004 Magic value used in comparison, consider replacing `"Hunter2"` with a constant variable | ||
magic_value_comparison.py:56:12: PLR2004 Magic value used in comparison, consider replacing `-2.0` with a constant variable | ||
| | ||
54 | pass | ||
55 | | ||
56 | if argc != -2.0: # [magic-value-comparison] | ||
| ^^^^ PLR2004 | ||
57 | pass | ||
| | ||
|
||
magic_value_comparison.py:59:12: PLR2004 Magic value used in comparison, consider replacing `+2.0` with a constant variable | ||
| | ||
57 | pass | ||
58 | | ||
59 | if input_password == "Hunter2": # correct | ||
| ^^^^^^^^^ PLR2004 | ||
59 | if argc != +2.0: # [magic-value-comparison] | ||
| ^^^^ PLR2004 | ||
60 | pass | ||
| | ||
|
||
magic_value_comparison.py:65:21: PLR2004 Magic value used in comparison, consider replacing `3.141592653589793238` with a constant variable | ||
magic_value_comparison.py:74:22: PLR2004 Magic value used in comparison, consider replacing `"Hunter2"` with a constant variable | ||
| | ||
72 | pass | ||
73 | | ||
74 | if input_password == "Hunter2": # correct | ||
| ^^^^^^^^^ PLR2004 | ||
75 | pass | ||
| | ||
|
||
magic_value_comparison.py:80:21: PLR2004 Magic value used in comparison, consider replacing `3.141592653589793238` with a constant variable | ||
| | ||
63 | pi_estimation = 3.14 | ||
64 | | ||
65 | if pi_estimation == 3.141592653589793238: # [magic-value-comparison] | ||
78 | pi_estimation = 3.14 | ||
79 | | ||
80 | if pi_estimation == 3.141592653589793238: # [magic-value-comparison] | ||
| ^^^^^^^^^^^^^^^^^^^^ PLR2004 | ||
66 | pass | ||
81 | pass | ||
| | ||
|
||
magic_value_comparison.py:77:18: PLR2004 Magic value used in comparison, consider replacing `b"something"` with a constant variable | ||
magic_value_comparison.py:92:18: PLR2004 Magic value used in comparison, consider replacing `b"something"` with a constant variable | ||
| | ||
75 | user_input = b"Hello, There!" | ||
76 | | ||
77 | if user_input == b"something": # correct | ||
90 | user_input = b"Hello, There!" | ||
91 | | ||
92 | if user_input == b"something": # correct | ||
| ^^^^^^^^^^^^ PLR2004 | ||
78 | pass | ||
93 | pass | ||
| | ||
|
||
|