-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new rule to check for useless quote escapes
- Loading branch information
1 parent
96b265c
commit 7f0bf50
Showing
11 changed files
with
939 additions
and
6 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
crates/ruff_linter/resources/test/fixtures/flake8_quotes/doubles_escaped_unnecessary.py
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
this_should_raise_Q100 = 'This is a \"string\"' | ||
this_should_raise_Q100 = 'This is \\ a \\\"string\"' | ||
this_is_fine = '"This" is a \"string\"' | ||
this_is_fine = "This is a 'string'" | ||
this_is_fine = "\"This\" is a 'string'" | ||
this_is_fine = r'This is a \"string\"' | ||
this_is_fine = R'This is a \"string\"' | ||
this_should_raise_Q100 = ( | ||
'This is a' | ||
'\"string\"' | ||
) | ||
|
||
# Same as above, but with f-strings | ||
f'This is a \"string\"' # Q100 | ||
f'This is \\ a \\\"string\"' # Q100 | ||
f'"This" is a \"string\"' | ||
f"This is a 'string'" | ||
f"\"This\" is a 'string'" | ||
fr'This is a \"string\"' | ||
fR'This is a \"string\"' | ||
this_should_raise_Q100 = ( | ||
f'This is a' | ||
f'\"string\"' # Q100 | ||
) | ||
|
||
# Nested f-strings (Python 3.12+) | ||
# | ||
# The first one is interesting because the fix for it is valid pre 3.12: | ||
# | ||
# f"'foo' {'nested'}" | ||
# | ||
# but as the actual string itself is invalid pre 3.12, we don't catch it. | ||
f'\"foo\" {'nested'}' # Q100 | ||
f'\"foo\" {f'nested'}' # Q100 | ||
f'\"foo\" {f'\"nested\"'} \"\"' # Q100 | ||
|
||
f'normal {f'nested'} normal' | ||
f'\"normal\" {f'nested'} normal' # Q100 | ||
f'\"normal\" {f'nested'} "double quotes"' | ||
f'\"normal\" {f'\"nested\" {'other'} normal'} "double quotes"' # Q100 | ||
f'\"normal\" {f'\"nested\" {'other'} "double quotes"'} normal' # Q100 |
39 changes: 39 additions & 0 deletions
39
crates/ruff_linter/resources/test/fixtures/flake8_quotes/singles_escaped_unnecessary.py
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
this_should_raise_Q100 = "This is a \'string\'" | ||
this_should_raise_Q100 = "'This' is a \'string\'" | ||
this_is_fine = 'This is a "string"' | ||
this_is_fine = '\'This\' is a "string"' | ||
this_is_fine = r"This is a \'string\'" | ||
this_is_fine = R"This is a \'string\'" | ||
this_should_raise_Q100 = ( | ||
"This is a" | ||
"\'string\'" | ||
) | ||
|
||
# Same as above, but with f-strings | ||
f"This is a \'string\'" # Q100 | ||
f"'This' is a \'string\'" # Q100 | ||
f'This is a "string"' | ||
f'\'This\' is a "string"' | ||
fr"This is a \'string\'" | ||
fR"This is a \'string\'" | ||
this_should_raise_Q100 = ( | ||
f"This is a" | ||
f"\'string\'" # Q100 | ||
) | ||
|
||
# Nested f-strings (Python 3.12+) | ||
# | ||
# The first one is interesting because the fix for it is valid pre 3.12: | ||
# | ||
# f'"foo" {"nested"}' | ||
# | ||
# but as the actual string itself is invalid pre 3.12, we don't catch it. | ||
f"\'foo\' {"foo"}" # Q100 | ||
f"\'foo\' {f"foo"}" # Q100 | ||
f"\'foo\' {f"\'foo\'"} \'\'" # Q100 | ||
|
||
f"normal {f"nested"} normal" | ||
f"\'normal\' {f"nested"} normal" # Q100 | ||
f"\'normal\' {f"nested"} 'single quotes'" | ||
f"\'normal\' {f"\'nested\' {"other"} normal"} 'single quotes'" # Q100 | ||
f"\'normal\' {f"\'nested\' {"other"} 'single quotes'"} normal" # Q100 |
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
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
Oops, something went wrong.