From 32432c6f55f943ca34505047a215945da9c64b26 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Sat, 7 Jan 2023 15:30:56 -0500 Subject: [PATCH] Tweak fixtures --- .../test/fixtures/flake8_simplify/SIM210.py | 11 +++---- .../test/fixtures/flake8_simplify/SIM211.py | 11 +++---- .../test/fixtures/flake8_simplify/SIM212.py | 10 +++--- src/flake8_simplify/plugins/ast_ifexp.rs | 3 +- ...ke8_simplify__tests__SIM210_SIM210.py.snap | 32 +++++++++---------- ...ke8_simplify__tests__SIM211_SIM211.py.snap | 32 +++++++++---------- ...ke8_simplify__tests__SIM212_SIM212.py.snap | 10 +++--- 7 files changed, 51 insertions(+), 58 deletions(-) diff --git a/resources/test/fixtures/flake8_simplify/SIM210.py b/resources/test/fixtures/flake8_simplify/SIM210.py index 87be0a7da0095a..f8a6e808fea137 100644 --- a/resources/test/fixtures/flake8_simplify/SIM210.py +++ b/resources/test/fixtures/flake8_simplify/SIM210.py @@ -1,10 +1,7 @@ +a = True if b else False # SIM210 -a = True if b else False # SIM210 - -a = True if b!=c else False # SIM210 - -a = True if b+c else False # SIM210 - -a = False if b else True +a = True if b != c else False # SIM210 +a = True if b + c else False # SIM210 +a = False if b else True # OK diff --git a/resources/test/fixtures/flake8_simplify/SIM211.py b/resources/test/fixtures/flake8_simplify/SIM211.py index 1823ac7fdfcaeb..645997adba6abf 100644 --- a/resources/test/fixtures/flake8_simplify/SIM211.py +++ b/resources/test/fixtures/flake8_simplify/SIM211.py @@ -1,10 +1,7 @@ +a = False if b else True # SIM211 -a = False if b else True # SIM211 - -a = False if b!=c else True # SIM211 -> SIM201 - -a = False if b+c else True # SIM211 - -a = True if b else False +a = False if b != c else True # SIM211 +a = False if b + c else True # SIM211 +a = True if b else False # OK diff --git a/resources/test/fixtures/flake8_simplify/SIM212.py b/resources/test/fixtures/flake8_simplify/SIM212.py index 617bd48b4dbc92..c39c4db88993d0 100644 --- a/resources/test/fixtures/flake8_simplify/SIM212.py +++ b/resources/test/fixtures/flake8_simplify/SIM212.py @@ -1,9 +1,7 @@ +c = b if not a else a # SIM212 -c = b if not a else a # SIM212 +c = b + c if not a else a # SIM212 -c = b+c if not a else a # SIM212 - -c = b if not x else a - -c = a if a else b +c = b if not x else a # OK +c = a if a else b # OK diff --git a/src/flake8_simplify/plugins/ast_ifexp.rs b/src/flake8_simplify/plugins/ast_ifexp.rs index b2b1e257305ba5..03a93f3924a0ec 100644 --- a/src/flake8_simplify/plugins/ast_ifexp.rs +++ b/src/flake8_simplify/plugins/ast_ifexp.rs @@ -107,7 +107,8 @@ pub fn twisted_arms_in_ifexpr( if !matches!(op, Unaryop::Not) { return; } - // Check if test operand and else branch is the same named variable + + // Check if the test operand and else branch use the same variable. let ExprKind::Name { id: test_id, .. } = &test_operand.node else { return; }; diff --git a/src/flake8_simplify/snapshots/ruff__flake8_simplify__tests__SIM210_SIM210.py.snap b/src/flake8_simplify/snapshots/ruff__flake8_simplify__tests__SIM210_SIM210.py.snap index 3ec3f3cbd953c5..db606bee62bb54 100644 --- a/src/flake8_simplify/snapshots/ruff__flake8_simplify__tests__SIM210_SIM210.py.snap +++ b/src/flake8_simplify/snapshots/ruff__flake8_simplify__tests__SIM210_SIM210.py.snap @@ -5,52 +5,52 @@ expression: checks - kind: IfExprWithTrueFalse: b location: - row: 2 + row: 1 column: 4 end_location: - row: 2 + row: 1 column: 24 fix: content: bool(b) location: - row: 2 + row: 1 column: 4 end_location: - row: 2 + row: 1 column: 24 parent: ~ - kind: IfExprWithTrueFalse: b != c location: - row: 4 + row: 3 column: 4 end_location: - row: 4 - column: 27 + row: 3 + column: 29 fix: content: bool(b != c) location: - row: 4 + row: 3 column: 4 end_location: - row: 4 - column: 27 + row: 3 + column: 29 parent: ~ - kind: IfExprWithTrueFalse: b + c location: - row: 6 + row: 5 column: 4 end_location: - row: 6 - column: 26 + row: 5 + column: 28 fix: content: bool(b + c) location: - row: 6 + row: 5 column: 4 end_location: - row: 6 - column: 26 + row: 5 + column: 28 parent: ~ diff --git a/src/flake8_simplify/snapshots/ruff__flake8_simplify__tests__SIM211_SIM211.py.snap b/src/flake8_simplify/snapshots/ruff__flake8_simplify__tests__SIM211_SIM211.py.snap index e9f332e710a60f..c09285d3497015 100644 --- a/src/flake8_simplify/snapshots/ruff__flake8_simplify__tests__SIM211_SIM211.py.snap +++ b/src/flake8_simplify/snapshots/ruff__flake8_simplify__tests__SIM211_SIM211.py.snap @@ -5,52 +5,52 @@ expression: checks - kind: IfExprWithFalseTrue: b location: - row: 2 + row: 1 column: 4 end_location: - row: 2 + row: 1 column: 24 fix: content: not b location: - row: 2 + row: 1 column: 4 end_location: - row: 2 + row: 1 column: 24 parent: ~ - kind: IfExprWithFalseTrue: b != c location: - row: 4 + row: 3 column: 4 end_location: - row: 4 - column: 27 + row: 3 + column: 29 fix: content: not b != c location: - row: 4 + row: 3 column: 4 end_location: - row: 4 - column: 27 + row: 3 + column: 29 parent: ~ - kind: IfExprWithFalseTrue: b + c location: - row: 6 + row: 5 column: 4 end_location: - row: 6 - column: 26 + row: 5 + column: 28 fix: content: not b + c location: - row: 6 + row: 5 column: 4 end_location: - row: 6 - column: 26 + row: 5 + column: 28 parent: ~ diff --git a/src/flake8_simplify/snapshots/ruff__flake8_simplify__tests__SIM212_SIM212.py.snap b/src/flake8_simplify/snapshots/ruff__flake8_simplify__tests__SIM212_SIM212.py.snap index f65d8fe3560a25..0fd162503d27fe 100644 --- a/src/flake8_simplify/snapshots/ruff__flake8_simplify__tests__SIM212_SIM212.py.snap +++ b/src/flake8_simplify/snapshots/ruff__flake8_simplify__tests__SIM212_SIM212.py.snap @@ -7,10 +7,10 @@ expression: checks - b - a location: - row: 2 + row: 1 column: 4 end_location: - row: 2 + row: 1 column: 21 fix: ~ parent: ~ @@ -19,11 +19,11 @@ expression: checks - b + c - a location: - row: 4 + row: 3 column: 4 end_location: - row: 4 - column: 23 + row: 3 + column: 25 fix: ~ parent: ~