-
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.
Fix
uncessary-coding-comment
fix when there's leading content (#6775)
Closes #6756 Including whitespace, code, and continuations.
- Loading branch information
Showing
12 changed files
with
121 additions
and
8 deletions.
There are no files selected for viewing
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,7 @@ | ||
""" | ||
# coding=utf8""" # empty comment | ||
|
||
""" | ||
Invalid coding declaration since it is nested inside a docstring | ||
The following empty comment tests for false positives as our implementation visits comments | ||
""" |
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,7 @@ | ||
# coding=utf8 | ||
print("Hello world") | ||
|
||
""" | ||
Regression test for https://github.com/astral-sh/ruff/issues/6756 | ||
The leading space must be removed to prevent invalid syntax. | ||
""" |
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,7 @@ | ||
# coding=utf8 | ||
print("Hello world") | ||
|
||
""" | ||
Regression test for https://github.com/astral-sh/ruff/issues/6756 | ||
The leading tab must be removed to prevent invalid syntax. | ||
""" |
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,6 @@ | ||
print("foo") # coding=utf8 | ||
print("Hello world") | ||
|
||
""" | ||
Invalid coding declaration due to a statement before the comment | ||
""" |
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,7 @@ | ||
x = 1 \ | ||
# coding=utf8 | ||
x = 2 | ||
|
||
""" | ||
Invalid coding declaration due to continuation on preceding line | ||
""" |
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
4 changes: 4 additions & 0 deletions
4
crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP009_10.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/src/rules/pyupgrade/mod.rs | ||
--- | ||
|
18 changes: 18 additions & 0 deletions
18
crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP009_6.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,18 @@ | ||
--- | ||
source: crates/ruff/src/rules/pyupgrade/mod.rs | ||
--- | ||
UP009_6.py:1:2: UP009 [*] UTF-8 encoding declaration is unnecessary | ||
| | ||
1 | # coding=utf8 | ||
| ^^^^^^^^^^^^^ UP009 | ||
2 | print("Hello world") | ||
| | ||
= help: Remove unnecessary coding comment | ||
|
||
ℹ Fix | ||
1 |- # coding=utf8 | ||
2 1 | print("Hello world") | ||
3 2 | | ||
4 3 | """ | ||
18 changes: 18 additions & 0 deletions
18
crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP009_7.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,18 @@ | ||
--- | ||
source: crates/ruff/src/rules/pyupgrade/mod.rs | ||
--- | ||
UP009_7.py:1:2: UP009 [*] UTF-8 encoding declaration is unnecessary | ||
| | ||
1 | # coding=utf8 | ||
| ^^^^^^^^^^^^^ UP009 | ||
2 | print("Hello world") | ||
| | ||
= help: Remove unnecessary coding comment | ||
|
||
ℹ Fix | ||
1 |- # coding=utf8 | ||
2 1 | print("Hello world") | ||
3 2 | | ||
4 3 | """ | ||
4 changes: 4 additions & 0 deletions
4
crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP009_8.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/src/rules/pyupgrade/mod.rs | ||
--- | ||
|
4 changes: 4 additions & 0 deletions
4
crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP009_9.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/src/rules/pyupgrade/mod.rs | ||
--- | ||
|