-
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.
Avoid
E703
for last expression in a cell (#8821)
## Summary This PR updates the `E703` rule to avoid flagging any semicolons if they're present after the last expression in a notebook cell. These are intended to hide the cell output. Part of #8669 ## Test Plan Add test notebook and update the snapshots.
- Loading branch information
1 parent
5b726f7
commit 8365d2e
Showing
6 changed files
with
212 additions
and
15 deletions.
There are no files selected for viewing
94 changes: 94 additions & 0 deletions
94
crates/ruff_linter/resources/test/fixtures/pycodestyle/E703.ipynb
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,94 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"id": "33faf7ad-a3fd-4ac4-a0c3-52e507ed49df", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"x = 1" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"id": "481fb4bf-c1b9-47da-927f-3cfdfe4b49ec", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Simple case\n", | ||
"x;" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"id": "2f0c65a5-0a0e-4080-afce-5a8ed0d706df", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Only skip the last expression\n", | ||
"x; # E703\n", | ||
"x;" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"id": "5a3fd75d-26d9-44f7-b013-1684aabfd0ae", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Nested expressions isn't relevant\n", | ||
"if True:\n", | ||
" x;" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 5, | ||
"id": "05eab5b9-e2ba-4954-8ef3-b035a79573fe", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Semicolons with multiple expressions\n", | ||
"x; x;" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 6, | ||
"id": "9cbbddc5-83fc-4fdb-81ab-53a3912ae898", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Comments, newlines and whitespace\n", | ||
"x; # comment\n", | ||
"\n", | ||
"# another comment" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python (ruff-playground)", | ||
"language": "python", | ||
"name": "ruff-playground" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.11.3" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
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
46 changes: 46 additions & 0 deletions
46
.../rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__E703_E703.ipynb.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,46 @@ | ||
--- | ||
source: crates/ruff_linter/src/rules/pycodestyle/mod.rs | ||
--- | ||
E703.ipynb:5:2: E703 [*] Statement ends with an unnecessary semicolon | ||
| | ||
3 | x; | ||
4 | # Only skip the last expression | ||
5 | x; # E703 | ||
| ^ E703 | ||
6 | x; | ||
7 | # Nested expressions isn't relevant | ||
| | ||
= help: Remove unnecessary semicolon | ||
|
||
ℹ Safe fix | ||
2 2 | # Simple case | ||
3 3 | x; | ||
4 4 | # Only skip the last expression | ||
5 |-x; # E703 | ||
5 |+x # E703 | ||
6 6 | x; | ||
7 7 | # Nested expressions isn't relevant | ||
8 8 | if True: | ||
|
||
E703.ipynb:9:6: E703 [*] Statement ends with an unnecessary semicolon | ||
| | ||
7 | # Nested expressions isn't relevant | ||
8 | if True: | ||
9 | x; | ||
| ^ E703 | ||
10 | # Semicolons with multiple expressions | ||
11 | x; x; | ||
| | ||
= help: Remove unnecessary semicolon | ||
|
||
ℹ Safe fix | ||
6 6 | x; | ||
7 7 | # Nested expressions isn't relevant | ||
8 8 | if True: | ||
9 |- x; | ||
9 |+ x | ||
10 10 | # Semicolons with multiple expressions | ||
11 11 | x; x; | ||
12 12 | # Comments, newlines and whitespace | ||
|
||
|