-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable token-based rules on source with syntax errors
- Loading branch information
1 parent
a26bd01
commit b7134c9
Showing
27 changed files
with
488 additions
and
106 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
crates/ruff_linter/resources/test/fixtures/flake8_implicit_str_concat/ISC_syntax_error.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,29 @@ | ||
# The lexer doesn't emit a string token if it's unterminated | ||
"a" "b | ||
"a" "b" "c | ||
"a" """b | ||
c""" "d | ||
|
||
# For f-strings, the `FStringRanges` won't contain the range for | ||
# unterminated f-strings. | ||
f"a" f"b | ||
f"a" f"b" f"c | ||
f"a" f"""b | ||
c""" f"d {e | ||
|
||
( | ||
"a" | ||
"b | ||
"c" | ||
"d" | ||
) | ||
|
||
|
||
# Triple-quoted strings, if unterminated, consume everything that comes after | ||
# the opening quote. So, no test code should raise the violation after this. | ||
( | ||
"""abc""" | ||
f"""def | ||
"g" "h" | ||
"i" "j" | ||
) |
26 changes: 26 additions & 0 deletions
26
crates/ruff_linter/resources/test/fixtures/pycodestyle/E30_syntax_error.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,26 @@ | ||
# Check for E30 errors in a file containing syntax errors with unclosed | ||
# parenthesis. | ||
|
||
def foo[T1, T2(): | ||
pass | ||
|
||
def bar(): | ||
pass | ||
|
||
|
||
|
||
class Foo: | ||
def __init__( | ||
pass | ||
def method(): | ||
pass | ||
|
||
foo = Foo( | ||
|
||
|
||
def top( | ||
def nested1(): | ||
pass | ||
def nested2(): | ||
pass | ||
|
13 changes: 13 additions & 0 deletions
13
crates/ruff_linter/resources/test/fixtures/pylint/invalid_characters_syntax_error.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,13 @@ | ||
# These test cases contain syntax errors. The characters within the unterminated | ||
# strings shouldn't be highlighted. | ||
|
||
# Before any syntax error | ||
b = '' | ||
# Unterminated string | ||
b = ' | ||
b = '' | ||
# Unterminated f-string | ||
b = f' | ||
b = f'' | ||
# Implicitly concatenated | ||
b = '' f'' ' |
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
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
67 changes: 67 additions & 0 deletions
67
...ts/ruff_linter__rules__flake8_implicit_str_concat__tests__ISC001_ISC_syntax_error.py.snap
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,67 @@ | ||
--- | ||
source: crates/ruff_linter/src/rules/flake8_implicit_str_concat/mod.rs | ||
--- | ||
ISC_syntax_error.py:3:1: ISC001 [*] Implicitly concatenated string literals on one line | ||
| | ||
1 | # The lexer doesn't emit a string token if it's unterminated | ||
2 | "a" "b | ||
3 | "a" "b" "c | ||
| ^^^^^^^ ISC001 | ||
4 | "a" """b | ||
5 | c""" "d | ||
| | ||
= help: Combine string literals | ||
|
||
ℹ Safe fix | ||
1 1 | # The lexer doesn't emit a string token if it's unterminated | ||
2 2 | "a" "b | ||
3 |-"a" "b" "c | ||
3 |+"ab" "c | ||
4 4 | "a" """b | ||
5 5 | c""" "d | ||
6 6 | | ||
|
||
ISC_syntax_error.py:4:1: ISC001 Implicitly concatenated string literals on one line | ||
| | ||
2 | "a" "b | ||
3 | "a" "b" "c | ||
4 | / "a" """b | ||
5 | | c""" "d | ||
| |____^ ISC001 | ||
6 | | ||
7 | # For f-strings, the `FStringRanges` won't contain the range for | ||
| | ||
= help: Combine string literals | ||
|
||
ISC_syntax_error.py:10:1: ISC001 [*] Implicitly concatenated string literals on one line | ||
| | ||
8 | # unterminated f-strings. | ||
9 | f"a" f"b | ||
10 | f"a" f"b" f"c | ||
| ^^^^^^^^^ ISC001 | ||
11 | f"a" f"""b | ||
12 | c""" f"d {e | ||
| | ||
= help: Combine string literals | ||
|
||
ℹ Safe fix | ||
7 7 | # For f-strings, the `FStringRanges` won't contain the range for | ||
8 8 | # unterminated f-strings. | ||
9 9 | f"a" f"b | ||
10 |-f"a" f"b" f"c | ||
10 |+f"ab" f"c | ||
11 11 | f"a" f"""b | ||
12 12 | c""" f"d {e | ||
13 13 | | ||
|
||
ISC_syntax_error.py:11:1: ISC001 Implicitly concatenated string literals on one line | ||
| | ||
9 | f"a" f"b | ||
10 | f"a" f"b" f"c | ||
11 | / f"a" f"""b | ||
12 | | c""" f"d {e | ||
| |____^ ISC001 | ||
13 | | ||
14 | ( | ||
| | ||
= help: Combine string literals |
4 changes: 4 additions & 0 deletions
4
...ts/ruff_linter__rules__flake8_implicit_str_concat__tests__ISC002_ISC_syntax_error.py.snap
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,4 @@ | ||
--- | ||
source: crates/ruff_linter/src/rules/flake8_implicit_str_concat/mod.rs | ||
--- | ||
|
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
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
21 changes: 21 additions & 0 deletions
21
...codestyle/snapshots/ruff_linter__rules__pycodestyle__tests__E301_E30_syntax_error.py.snap
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,21 @@ | ||
--- | ||
source: crates/ruff_linter/src/rules/pycodestyle/mod.rs | ||
--- | ||
E30_syntax_error.py:15:5: E301 [*] Expected 1 blank line, found 0 | ||
| | ||
13 | def __init__( | ||
14 | pass | ||
15 | def method(): | ||
| ^^^ E301 | ||
16 | pass | ||
| | ||
= help: Add missing blank line | ||
|
||
ℹ Safe fix | ||
12 12 | class Foo: | ||
13 13 | def __init__( | ||
14 14 | pass | ||
15 |+ | ||
15 16 | def method(): | ||
16 17 | pass | ||
17 18 | |
Oops, something went wrong.