diff --git a/crates/ruff/resources/test/fixtures/pylint/compare_to_empty_string.py b/crates/ruff/resources/test/fixtures/pylint/compare_to_empty_string.py index 1ab940de7b..fbf3abd1e9 100644 --- a/crates/ruff/resources/test/fixtures/pylint/compare_to_empty_string.py +++ b/crates/ruff/resources/test/fixtures/pylint/compare_to_empty_string.py @@ -1,8 +1,11 @@ -x = "" -y = "hello" +x = "a string" +y = "another string" -if x == "": # [compare-to-empty-string] +if x is "" or x == "": print("x is an empty string") -if y != "": # [compare-to-empty-string] +if y is not "" or y != "": print("y is not an empty string") + +if x and not y: + print("x is not an empty string, but y is an empty string") diff --git a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLC1901_compare_to_empty_string.py.snap b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLC1901_compare_to_empty_string.py.snap index a846c5d79d..7a7db84792 100644 --- a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLC1901_compare_to_empty_string.py.snap +++ b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLC1901_compare_to_empty_string.py.snap @@ -3,7 +3,10 @@ source: crates/ruff/src/rules/pylint/mod.rs expression: diagnostics --- - kind: - CompareToEmptyString: ~ + CompareToEmptyString: + lhs: x + op: Is + rhs: "\"\"" location: row: 4 column: 3 @@ -13,7 +16,23 @@ expression: diagnostics fix: ~ parent: ~ - kind: - CompareToEmptyString: ~ + CompareToEmptyString: + lhs: x + op: Eq + rhs: "\"\"" + location: + row: 4 + column: 14 + end_location: + row: 4 + column: 15 + fix: ~ + parent: ~ +- kind: + CompareToEmptyString: + lhs: y + op: IsNot + rhs: "\"\"" location: row: 7 column: 3 @@ -22,4 +41,17 @@ expression: diagnostics column: 4 fix: ~ parent: ~ +- kind: + CompareToEmptyString: + lhs: y + op: NotEq + rhs: "\"\"" + location: + row: 7 + column: 18 + end_location: + row: 7 + column: 19 + fix: ~ + parent: ~