Enable suppression of magic values by type (#1987)

Closes #1949.
This commit is contained in:
Charlie Marsh
2023-01-18 20:44:24 -05:00
committed by GitHub
parent 34412a0a01
commit d33424ec9d
16 changed files with 287 additions and 62 deletions

View File

@@ -1,71 +1,69 @@
"""Check that magic values are not used in comparisons"""
import cmath
"""Check that magic values are not used in comparisons."""
user_input = 10
if 10 > user_input: # [magic-value-comparison]
if 10 > user_input: # [magic-value-comparison]
pass
if 10 == 100: # [comparison-of-constants] R0133
if 10 == 100: # [comparison-of-constants] R0133
pass
if 1 == 3: # [comparison-of-constants] R0133
if 1 == 3: # [comparison-of-constants] R0133
pass
x = 0
if 4 == 3 == x: # [comparison-of-constants] R0133
if 4 == 3 == x: # [comparison-of-constants] R0133
pass
time_delta = 7224
ONE_HOUR = 3600
if time_delta > ONE_HOUR: # correct
if time_delta > ONE_HOUR: # correct
pass
argc = 1
if argc != -1: # correct
if argc != -1: # correct
pass
if argc != 0: # correct
if argc != 0: # correct
pass
if argc != 1: # correct
if argc != 1: # correct
pass
if argc != 2: # [magic-value-comparison]
if argc != 2: # [magic-value-comparison]
pass
if __name__ == "__main__": # correct
if __name__ == "__main__": # correct
pass
ADMIN_PASSWORD = "SUPERSECRET"
input_password = "password"
if input_password == "": # correct
if input_password == "": # correct
pass
if input_password == ADMIN_PASSWORD: # correct
if input_password == ADMIN_PASSWORD: # correct
pass
if input_password == "Hunter2": # [magic-value-comparison]
if input_password == "Hunter2": # [magic-value-comparison]
pass
PI = 3.141592653589793238
pi_estimation = 3.14
if pi_estimation == 3.141592653589793238: # [magic-value-comparison]
if pi_estimation == 3.141592653589793238: # [magic-value-comparison]
pass
if pi_estimation == PI: # correct
if pi_estimation == PI: # correct
pass
HELLO_WORLD = b"Hello, World!"
user_input = b"Hello, There!"
if user_input == b"something": # [magic-value-comparison]
if user_input == b"something": # [magic-value-comparison]
pass
if user_input == HELLO_WORLD: # correct
if user_input == HELLO_WORLD: # correct
pass