diff --git a/resources/test/fixtures/E711.py b/resources/test/fixtures/E711.py index 932a7fa9d5..0b141efcdc 100644 --- a/resources/test/fixtures/E711.py +++ b/resources/test/fixtures/E711.py @@ -1,11 +1,50 @@ -if var == None: +#: E711 +if res == None: + pass +#: E711 +if res != None: + pass +#: E711 +if None == res: + pass +#: E711 +if None != res: + pass +#: E711 +if res[1] == None: + pass +#: E711 +if res[1] != None: + pass +#: E711 +if None != res[1]: + pass +#: E711 +if None == res[1]: pass -if None != var: +#: Okay +if x not in y: pass -if var is None: +if not (X in Y or X is Z): pass -if None is not var: +if not (X in Y): pass + +if x is not y: + pass + +if X is not Y is not Z: + pass + +if TrueElement.get_element(True) == TrueElement.get_element(False): + pass + +if (True) == TrueElement or x == TrueElement: + pass + +assert (not foo) in bar +assert {"x": not foo} in bar +assert [42, not foo] in bar diff --git a/resources/test/fixtures/E712.py b/resources/test/fixtures/E712.py index bf84a8163e..a3f97e19c7 100644 --- a/resources/test/fixtures/E712.py +++ b/resources/test/fixtures/E712.py @@ -1,14 +1,46 @@ -if var == True: +#: E712 +if res == True: + pass +#: E712 +if res != False: + pass +#: E712 +if True != res: + pass +#: E712 +if False == res: + pass +#: E712 +if res[1] == True: + pass +#: E712 +if res[1] != False: + pass +#: E712 +var = 1 if cond == True else -1 if cond == False else cond +#: E712 +if (True) == TrueElement or x == TrueElement: pass -if False != var: +#: Okay +if x not in y: pass -if var != False != True: +if not (X in Y or X is Z): pass -if var is True: +if not (X in Y): pass -if False is not var: +if x is not y: pass + +if X is not Y is not Z: + pass + +if TrueElement.get_element(True) == TrueElement.get_element(False): + pass + +assert (not foo) in bar +assert {"x": not foo} in bar +assert [42, not foo] in bar diff --git a/resources/test/fixtures/E713.py b/resources/test/fixtures/E713.py index 216a99c68b..12b249261d 100644 --- a/resources/test/fixtures/E713.py +++ b/resources/test/fixtures/E713.py @@ -1,7 +1,38 @@ -my_list = [1, 2, 3] -if not num in my_list: - print(num) +#: E713 +if not X in Y: + pass +#: E713 +if not X.B in Y: + pass +#: E713 +if not X in Y and Z == "zero": + pass +#: E713 +if X == "zero" or not Y in Z: + pass +#: E713 +if not (X in Y): + pass -my_list = [1, 2, 3] -if num not in my_list: - print(num) +#: Okay +if x not in y: + pass + +if not (X in Y or X is Z): + pass + +if x is not y: + pass + +if X is not Y is not Z: + pass + +if TrueElement.get_element(True) == TrueElement.get_element(False): + pass + +if (True) == TrueElement or x == TrueElement: + pass + +assert (not foo) in bar +assert {"x": not foo} in bar +assert [42, not foo] in bar diff --git a/resources/test/fixtures/E714.py b/resources/test/fixtures/E714.py index fb692f0a19..68112c4954 100644 --- a/resources/test/fixtures/E714.py +++ b/resources/test/fixtures/E714.py @@ -1,5 +1,38 @@ -if not user is None: - print(user.name) +#: E714 +if not X is Y: + pass +#: E714 +if not X.B is Y: + pass +#: E714 +if not X is Y is not Z: + pass -if user is not None: - print(user.name) +#: Okay +if not X is not Y: + pass + +if x not in y: + pass + +if not (X in Y or X is Z): + pass + +if not (X in Y): + pass + +if x is not y: + pass + +if X is not Y is not Z: + pass + +if TrueElement.get_element(True) == TrueElement.get_element(False): + pass + +if (True) == TrueElement or x == TrueElement: + pass + +assert (not foo) in bar +assert {"x": not foo} in bar +assert [42, not foo] in bar diff --git a/resources/test/fixtures/E721.py b/resources/test/fixtures/E721.py index 9b379fefc8..f06bed4e38 100644 --- a/resources/test/fixtures/E721.py +++ b/resources/test/fixtures/E721.py @@ -41,6 +41,14 @@ assert type(res) == type(()) #: E201 E202 E721 assert type(res) == type((0,)) -assert type(res) == type(res) -assert type(res) == type(int) -assert type(res) == type() +#: Okay +import types + +if isinstance(res, int): + pass +if isinstance(res, str): + pass +if isinstance(res, types.MethodType): + pass +if type(a) != type(b) or type(a) == type(ccc): + pass diff --git a/resources/test/fixtures/E722.py b/resources/test/fixtures/E722.py index a0caee917c..c646c8b82b 100644 --- a/resources/test/fixtures/E722.py +++ b/resources/test/fixtures/E722.py @@ -1,9 +1,33 @@ +#: E722 try: pass except: pass - +#: E722 try: pass except Exception: pass +except: + pass +#: E722 +try: + pass +except: + pass +#: Okay +fake_code = """" +try: + do_something() +except: + pass +""" +try: + pass +except Exception: + pass +#: Okay +from . import compute_type + +if compute_type(foo) == 5: + pass diff --git a/resources/test/fixtures/E731.py b/resources/test/fixtures/E731.py index 13b151738b..5949da4a43 100644 --- a/resources/test/fixtures/E731.py +++ b/resources/test/fixtures/E731.py @@ -1,6 +1,21 @@ -from typing import Callable, Iterable +#: E731 +f = lambda x: 2 * x +#: E731 +f = lambda x: 2 * x +#: E731 +while False: + this = lambda y, z: 2 * x -a = lambda x: x**2 -b = map(lambda x: 2 * x, range(3)) -c: Callable = lambda x: x**2 -d: Iterable = map(lambda x: 2 * x, range(3)) + +f = object() +#: E731 +f.method = lambda: "Method" + +f = {} +#: E731 +f["a"] = lambda x: x ** 2 + +f = [] +f.append(lambda x: x ** 2) + +lambda: "no-op" diff --git a/src/ast/checks.rs b/src/ast/checks.rs index 81baaf50d4..823be2eb8d 100644 --- a/src/ast/checks.rs +++ b/src/ast/checks.rs @@ -42,18 +42,20 @@ pub fn check_not_tests( if matches!(op, Unaryop::Not) { if let ExprKind::Compare { ops, .. } = &operand.node { - match ops[..] { - [Cmpop::In] => { - if check_not_in { - checks.push(Check::new(CheckKind::NotInTest, operand.location)); + for op in ops { + match op { + Cmpop::In => { + if check_not_in { + checks.push(Check::new(CheckKind::NotInTest, operand.location)); + } } - } - [Cmpop::Is] => { - if check_not_is { - checks.push(Check::new(CheckKind::NotIsTest, operand.location)); + Cmpop::Is => { + if check_not_is { + checks.push(Check::new(CheckKind::NotIsTest, operand.location)); + } } + _ => {} } - _ => {} } } } diff --git a/src/snapshots/ruff__linter__tests__e711.snap b/src/snapshots/ruff__linter__tests__e711.snap index 6f78bd9774..21466b6be3 100644 --- a/src/snapshots/ruff__linter__tests__e711.snap +++ b/src/snapshots/ruff__linter__tests__e711.snap @@ -5,13 +5,49 @@ expression: checks - kind: NoneComparison: Eq location: - row: 1 + row: 2 column: 11 fix: ~ - kind: NoneComparison: NotEq location: - row: 4 + row: 5 + column: 11 + fix: ~ +- kind: + NoneComparison: Eq + location: + row: 8 + column: 4 + fix: ~ +- kind: + NoneComparison: NotEq + location: + row: 11 + column: 4 + fix: ~ +- kind: + NoneComparison: Eq + location: + row: 14 + column: 14 + fix: ~ +- kind: + NoneComparison: NotEq + location: + row: 17 + column: 14 + fix: ~ +- kind: + NoneComparison: NotEq + location: + row: 20 + column: 4 + fix: ~ +- kind: + NoneComparison: Eq + location: + row: 23 column: 4 fix: ~ diff --git a/src/snapshots/ruff__linter__tests__e712.snap b/src/snapshots/ruff__linter__tests__e712.snap index 0b9d0508fa..2563ad5296 100644 --- a/src/snapshots/ruff__linter__tests__e712.snap +++ b/src/snapshots/ruff__linter__tests__e712.snap @@ -7,7 +7,7 @@ expression: checks - true - Eq location: - row: 1 + row: 2 column: 11 fix: ~ - kind: @@ -15,15 +15,7 @@ expression: checks - false - NotEq location: - row: 4 - column: 4 - fix: ~ -- kind: - TrueFalseComparison: - - false - - NotEq - location: - row: 7 + row: 5 column: 11 fix: ~ - kind: @@ -31,7 +23,55 @@ expression: checks - true - NotEq location: - row: 7 + row: 8 + column: 4 + fix: ~ +- kind: + TrueFalseComparison: + - false + - Eq + location: + row: 11 + column: 4 + fix: ~ +- kind: + TrueFalseComparison: + - true + - Eq + location: + row: 14 + column: 14 + fix: ~ +- kind: + TrueFalseComparison: + - false + - NotEq + location: + row: 17 + column: 14 + fix: ~ +- kind: + TrueFalseComparison: + - true + - Eq + location: + row: 20 column: 20 fix: ~ +- kind: + TrueFalseComparison: + - false + - Eq + location: + row: 20 + column: 44 + fix: ~ +- kind: + TrueFalseComparison: + - true + - Eq + location: + row: 22 + column: 5 + fix: ~ diff --git a/src/snapshots/ruff__linter__tests__e713.snap b/src/snapshots/ruff__linter__tests__e713.snap index 34102e6730..47a343d46e 100644 --- a/src/snapshots/ruff__linter__tests__e713.snap +++ b/src/snapshots/ruff__linter__tests__e713.snap @@ -5,6 +5,26 @@ expression: checks - kind: NotInTest location: row: 2 + column: 10 + fix: ~ +- kind: NotInTest + location: + row: 5 column: 12 fix: ~ +- kind: NotInTest + location: + row: 8 + column: 10 + fix: ~ +- kind: NotInTest + location: + row: 11 + column: 25 + fix: ~ +- kind: NotInTest + location: + row: 14 + column: 11 + fix: ~ diff --git a/src/snapshots/ruff__linter__tests__e714.snap b/src/snapshots/ruff__linter__tests__e714.snap index a7e80101c4..6ab33efb7f 100644 --- a/src/snapshots/ruff__linter__tests__e714.snap +++ b/src/snapshots/ruff__linter__tests__e714.snap @@ -4,7 +4,17 @@ expression: checks --- - kind: NotIsTest location: - row: 1 - column: 13 + row: 2 + column: 10 + fix: ~ +- kind: NotIsTest + location: + row: 5 + column: 12 + fix: ~ +- kind: NotIsTest + location: + row: 8 + column: 10 fix: ~ diff --git a/src/snapshots/ruff__linter__tests__e722.snap b/src/snapshots/ruff__linter__tests__e722.snap index 89f75e0fc3..555d04866b 100644 --- a/src/snapshots/ruff__linter__tests__e722.snap +++ b/src/snapshots/ruff__linter__tests__e722.snap @@ -4,7 +4,17 @@ expression: checks --- - kind: DoNotUseBareExcept location: - row: 3 + row: 4 + column: 1 + fix: ~ +- kind: DoNotUseBareExcept + location: + row: 11 + column: 1 + fix: ~ +- kind: DoNotUseBareExcept + location: + row: 16 column: 1 fix: ~ diff --git a/src/snapshots/ruff__linter__tests__e731.snap b/src/snapshots/ruff__linter__tests__e731.snap index 19c6fc7bc4..5c0bcd6c78 100644 --- a/src/snapshots/ruff__linter__tests__e731.snap +++ b/src/snapshots/ruff__linter__tests__e731.snap @@ -4,12 +4,27 @@ expression: checks --- - kind: DoNotAssignLambda location: - row: 3 + row: 2 column: 1 fix: ~ - kind: DoNotAssignLambda location: - row: 5 + row: 4 + column: 1 + fix: ~ +- kind: DoNotAssignLambda + location: + row: 7 + column: 5 + fix: ~ +- kind: DoNotAssignLambda + location: + row: 12 + column: 1 + fix: ~ +- kind: DoNotAssignLambda + location: + row: 16 column: 1 fix: ~