-
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.
## Summary This adds an autofix for PIE800 (unnecessary spread) -- whenever we see a `**{...}` inside another dictionary literal, just delete the `**{` and `}` to inline the key-value pairs. So `{"a": "b", **{"c": "d"}}` becomes just `{"a": "b", "c": "d"}`. I have enabled this just for preview mode. ## Test Plan Updated the preview snapshot test.
- Loading branch information
Showing
6 changed files
with
257 additions
and
31 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
crates/ruff_linter/resources/test/fixtures/flake8_pie/PIE800.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
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
134 changes: 134 additions & 0 deletions
134
...lake8_pie/snapshots/ruff_linter__rules__flake8_pie__tests__preview__PIE800_PIE800.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,134 @@ | ||
--- | ||
source: crates/ruff_linter/src/rules/flake8_pie/mod.rs | ||
--- | ||
PIE800.py:1:14: PIE800 [*] Unnecessary spread `**` | ||
| | ||
1 | {"foo": 1, **{"bar": 1}} # PIE800 | ||
| ^^^^^^^^^^ PIE800 | ||
2 | | ||
3 | {**{"bar": 10}, "a": "b"} # PIE800 | ||
| | ||
= help: Remove unnecessary dict | ||
|
||
ℹ Safe fix | ||
1 |-{"foo": 1, **{"bar": 1}} # PIE800 | ||
1 |+{"foo": 1, "bar": 1} # PIE800 | ||
2 2 | | ||
3 3 | {**{"bar": 10}, "a": "b"} # PIE800 | ||
4 4 | | ||
|
||
PIE800.py:3:4: PIE800 [*] Unnecessary spread `**` | ||
| | ||
1 | {"foo": 1, **{"bar": 1}} # PIE800 | ||
2 | | ||
3 | {**{"bar": 10}, "a": "b"} # PIE800 | ||
| ^^^^^^^^^^^ PIE800 | ||
4 | | ||
5 | foo({**foo, **{"bar": True}}) # PIE800 | ||
| | ||
= help: Remove unnecessary dict | ||
|
||
ℹ Safe fix | ||
1 1 | {"foo": 1, **{"bar": 1}} # PIE800 | ||
2 2 | | ||
3 |-{**{"bar": 10}, "a": "b"} # PIE800 | ||
3 |+{"bar": 10, "a": "b"} # PIE800 | ||
4 4 | | ||
5 5 | foo({**foo, **{"bar": True}}) # PIE800 | ||
6 6 | | ||
|
||
PIE800.py:5:15: PIE800 [*] Unnecessary spread `**` | ||
| | ||
3 | {**{"bar": 10}, "a": "b"} # PIE800 | ||
4 | | ||
5 | foo({**foo, **{"bar": True}}) # PIE800 | ||
| ^^^^^^^^^^^^^ PIE800 | ||
6 | | ||
7 | {**foo, **{"bar": 10}} # PIE800 | ||
| | ||
= help: Remove unnecessary dict | ||
|
||
ℹ Safe fix | ||
2 2 | | ||
3 3 | {**{"bar": 10}, "a": "b"} # PIE800 | ||
4 4 | | ||
5 |-foo({**foo, **{"bar": True}}) # PIE800 | ||
5 |+foo({**foo, "bar": True}) # PIE800 | ||
6 6 | | ||
7 7 | {**foo, **{"bar": 10}} # PIE800 | ||
8 8 | | ||
|
||
PIE800.py:7:11: PIE800 [*] Unnecessary spread `**` | ||
| | ||
5 | foo({**foo, **{"bar": True}}) # PIE800 | ||
6 | | ||
7 | {**foo, **{"bar": 10}} # PIE800 | ||
| ^^^^^^^^^^^ PIE800 | ||
8 | | ||
9 | { # PIE800 | ||
| | ||
= help: Remove unnecessary dict | ||
|
||
ℹ Safe fix | ||
4 4 | | ||
5 5 | foo({**foo, **{"bar": True}}) # PIE800 | ||
6 6 | | ||
7 |-{**foo, **{"bar": 10}} # PIE800 | ||
7 |+{**foo, "bar": 10} # PIE800 | ||
8 8 | | ||
9 9 | { # PIE800 | ||
10 10 | "a": "b", | ||
|
||
PIE800.py:12:7: PIE800 [*] Unnecessary spread `**` | ||
| | ||
10 | "a": "b", | ||
11 | # Preserve | ||
12 | **{ | ||
| _______^ | ||
13 | | # all | ||
14 | | "bar": 10, # the | ||
15 | | # comments | ||
16 | | }, | ||
| |_____^ PIE800 | ||
17 | } | ||
| | ||
= help: Remove unnecessary dict | ||
|
||
ℹ Safe fix | ||
9 9 | { # PIE800 | ||
10 10 | "a": "b", | ||
11 11 | # Preserve | ||
12 |- **{ | ||
12 |+ | ||
13 13 | # all | ||
14 |- "bar": 10, # the | ||
14 |+ "bar": 10 # the | ||
15 15 | # comments | ||
16 |- }, | ||
16 |+ , | ||
17 17 | } | ||
18 18 | | ||
19 19 | {**foo, **buzz, **{bar: 10}} # PIE800 | ||
|
||
PIE800.py:19:19: PIE800 [*] Unnecessary spread `**` | ||
| | ||
17 | } | ||
18 | | ||
19 | {**foo, **buzz, **{bar: 10}} # PIE800 | ||
| ^^^^^^^^^ PIE800 | ||
20 | | ||
21 | {**foo, "bar": True } # OK | ||
| | ||
= help: Remove unnecessary dict | ||
|
||
ℹ Safe fix | ||
16 16 | }, | ||
17 17 | } | ||
18 18 | | ||
19 |-{**foo, **buzz, **{bar: 10}} # PIE800 | ||
19 |+{**foo, **buzz, bar: 10} # PIE800 | ||
20 20 | | ||
21 21 | {**foo, "bar": True } # OK | ||
22 22 | | ||
|
||
|