Add Applicability to flake8_comma fixes (#5127)

## Summary

Fixes some of #4184
This commit is contained in:
Evan Rittenhouse 2023-06-15 15:49:54 -05:00 committed by GitHub
parent 107a295af4
commit 6143065fc2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 45 additions and 47 deletions

View file

@ -326,8 +326,7 @@ pub(crate) fn trailing_commas(
let comma = prev.spanned.unwrap();
let mut diagnostic = Diagnostic::new(ProhibitedTrailingComma, comma.1);
if settings.rules.should_fix(Rule::ProhibitedTrailingComma) {
#[allow(deprecated)]
diagnostic.set_fix(Fix::unspecified(Edit::range_deletion(diagnostic.range())));
diagnostic.set_fix(Fix::automatic(Edit::range_deletion(diagnostic.range())));
}
diagnostics.push(diagnostic);
}
@ -367,8 +366,7 @@ pub(crate) fn trailing_commas(
// removing any brackets in the same linter pass - doing both at the same time could
// lead to a syntax error.
let contents = locator.slice(missing_comma.1);
#[allow(deprecated)]
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
diagnostic.set_fix(Fix::automatic(Edit::range_replacement(
format!("{contents},"),
missing_comma.1,
)));

View file

@ -12,7 +12,7 @@ COM81.py:4:18: COM812 [*] Trailing comma missing
|
= help: Add trailing comma
Suggested fix
Fix
1 1 | # ==> bad_function_call.py <==
2 2 | bad_function_call(
3 3 | param1='test',
@ -32,7 +32,7 @@ COM81.py:10:6: COM812 [*] Trailing comma missing
|
= help: Add trailing comma
Suggested fix
Fix
7 7 | bad_list = [
8 8 | 1,
9 9 | 2,
@ -53,7 +53,7 @@ COM81.py:16:6: COM812 [*] Trailing comma missing
|
= help: Add trailing comma
Suggested fix
Fix
13 13 | bad_list_with_comment = [
14 14 | 1,
15 15 | 2,
@ -72,7 +72,7 @@ COM81.py:23:6: COM812 [*] Trailing comma missing
|
= help: Add trailing comma
Suggested fix
Fix
20 20 | bad_list_with_extra_empty = [
21 21 | 1,
22 22 | 2,
@ -159,7 +159,7 @@ COM81.py:70:8: COM812 [*] Trailing comma missing
|
= help: Add trailing comma
Suggested fix
Fix
67 67 | pass
68 68 |
69 69 | {'foo': foo}['foo'](
@ -178,7 +178,7 @@ COM81.py:78:8: COM812 [*] Trailing comma missing
|
= help: Add trailing comma
Suggested fix
Fix
75 75 | )
76 76 |
77 77 | (foo)(
@ -197,7 +197,7 @@ COM81.py:86:8: COM812 [*] Trailing comma missing
|
= help: Add trailing comma
Suggested fix
Fix
83 83 | )
84 84 |
85 85 | [foo][0](
@ -217,7 +217,7 @@ COM81.py:152:6: COM812 [*] Trailing comma missing
|
= help: Add trailing comma
Suggested fix
Fix
149 149 |
150 150 | # ==> keyword_before_parenth_form/base_bad.py <==
151 151 | from x import (
@ -237,7 +237,7 @@ COM81.py:158:11: COM812 [*] Trailing comma missing
|
= help: Add trailing comma
Suggested fix
Fix
155 155 | assert(
156 156 | SyntaxWarning,
157 157 | ThrownHere,
@ -258,7 +258,7 @@ COM81.py:293:15: COM812 [*] Trailing comma missing
|
= help: Add trailing comma
Suggested fix
Fix
290 290 |
291 291 | # ==> multiline_bad_dict.py <==
292 292 | multiline_bad_dict = {
@ -279,7 +279,7 @@ COM81.py:304:14: COM812 [*] Trailing comma missing
|
= help: Add trailing comma
Suggested fix
Fix
301 301 |
302 302 | def func_bad(
303 303 | a = 3,
@ -300,7 +300,7 @@ COM81.py:310:14: COM812 [*] Trailing comma missing
|
= help: Add trailing comma
Suggested fix
Fix
307 307 |
308 308 | # ==> multiline_bad_function_one_param.py <==
309 309 | def func(
@ -319,7 +319,7 @@ COM81.py:316:10: COM812 [*] Trailing comma missing
|
= help: Add trailing comma
Suggested fix
Fix
313 313 |
314 314 |
315 315 | func(
@ -339,7 +339,7 @@ COM81.py:322:15: COM812 [*] Trailing comma missing
|
= help: Add trailing comma
Suggested fix
Fix
319 319 | # ==> multiline_bad_or_dict.py <==
320 320 | multiline_bad_or_dict = {
321 321 | "good": True or False,
@ -359,7 +359,7 @@ COM81.py:368:15: COM812 [*] Trailing comma missing
|
= help: Add trailing comma
Suggested fix
Fix
365 365 |
366 366 | multiline_index_access[
367 367 | "probably fine",
@ -379,7 +379,7 @@ COM81.py:375:15: COM812 [*] Trailing comma missing
|
= help: Add trailing comma
Suggested fix
Fix
372 372 | "fine",
373 373 | "fine",
374 374 | :
@ -399,7 +399,7 @@ COM81.py:404:15: COM812 [*] Trailing comma missing
|
= help: Add trailing comma
Suggested fix
Fix
401 401 | "fine",
402 402 | "fine"
403 403 | :
@ -419,7 +419,7 @@ COM81.py:432:15: COM812 [*] Trailing comma missing
|
= help: Add trailing comma
Suggested fix
Fix
429 429 | "fine"
430 430 | :
431 431 | "fine",
@ -439,7 +439,7 @@ COM81.py:485:21: COM819 [*] Trailing comma prohibited
|
= help: Remove trailing comma
Suggested fix
Fix
482 482 | )
483 483 |
484 484 | # ==> prohibited.py <==
@ -460,7 +460,7 @@ COM81.py:487:13: COM819 [*] Trailing comma prohibited
|
= help: Remove trailing comma
Suggested fix
Fix
484 484 | # ==> prohibited.py <==
485 485 | foo = ['a', 'b', 'c',]
486 486 |
@ -480,7 +480,7 @@ COM81.py:489:18: COM819 [*] Trailing comma prohibited
|
= help: Remove trailing comma
Suggested fix
Fix
486 486 |
487 487 | bar = { a: b,}
488 488 |
@ -501,7 +501,7 @@ COM81.py:494:6: COM819 [*] Trailing comma prohibited
|
= help: Remove trailing comma
Suggested fix
Fix
491 491 |
492 492 | (0,)
493 493 |
@ -522,7 +522,7 @@ COM81.py:496:21: COM819 [*] Trailing comma prohibited
|
= help: Remove trailing comma
Suggested fix
Fix
493 493 |
494 494 | (0, 1,)
495 495 |
@ -543,7 +543,7 @@ COM81.py:498:13: COM819 [*] Trailing comma prohibited
|
= help: Remove trailing comma
Suggested fix
Fix
495 495 |
496 496 | foo = ['a', 'b', 'c', ]
497 497 |
@ -563,7 +563,7 @@ COM81.py:500:18: COM819 [*] Trailing comma prohibited
|
= help: Remove trailing comma
Suggested fix
Fix
497 497 |
498 498 | bar = { a: b, }
499 499 |
@ -584,7 +584,7 @@ COM81.py:505:6: COM819 [*] Trailing comma prohibited
|
= help: Remove trailing comma
Suggested fix
Fix
502 502 |
503 503 | (0, )
504 504 |
@ -605,7 +605,7 @@ COM81.py:511:10: COM819 [*] Trailing comma prohibited
|
= help: Remove trailing comma
Suggested fix
Fix
508 508 |
509 509 | image[:,]
510 510 |
@ -626,7 +626,7 @@ COM81.py:513:9: COM819 [*] Trailing comma prohibited
|
= help: Remove trailing comma
Suggested fix
Fix
510 510 |
511 511 | image[:,:,]
512 512 |
@ -647,7 +647,7 @@ COM81.py:519:13: COM812 [*] Trailing comma missing
|
= help: Add trailing comma
Suggested fix
Fix
516 516 | def function(
517 517 | foo,
518 518 | bar,
@ -668,7 +668,7 @@ COM81.py:526:10: COM812 [*] Trailing comma missing
|
= help: Add trailing comma
Suggested fix
Fix
523 523 | def function(
524 524 | foo,
525 525 | bar,
@ -689,7 +689,7 @@ COM81.py:534:16: COM812 [*] Trailing comma missing
|
= help: Add trailing comma
Suggested fix
Fix
531 531 | foo,
532 532 | bar,
533 533 | *args,
@ -709,7 +709,7 @@ COM81.py:541:13: COM812 [*] Trailing comma missing
|
= help: Add trailing comma
Suggested fix
Fix
538 538 | result = function(
539 539 | foo,
540 540 | bar,
@ -729,7 +729,7 @@ COM81.py:547:24: COM812 [*] Trailing comma missing
|
= help: Add trailing comma
Suggested fix
Fix
544 544 | result = function(
545 545 | foo,
546 546 | bar,
@ -750,7 +750,7 @@ COM81.py:554:15: COM812 [*] Trailing comma missing
|
= help: Add trailing comma
Suggested fix
Fix
551 551 | ham,
552 552 | spam,
553 553 | *args,
@ -769,7 +769,7 @@ COM81.py:561:13: COM812 [*] Trailing comma missing
|
= help: Add trailing comma
Suggested fix
Fix
558 558 | # In python 3.5 if it's not a function def, commas are mandatory.
559 559 |
560 560 | foo(
@ -788,7 +788,7 @@ COM81.py:565:13: COM812 [*] Trailing comma missing
|
= help: Add trailing comma
Suggested fix
Fix
562 562 | )
563 563 |
564 564 | {
@ -807,7 +807,7 @@ COM81.py:573:10: COM812 [*] Trailing comma missing
|
= help: Add trailing comma
Suggested fix
Fix
570 570 | )
571 571 |
572 572 | {
@ -826,7 +826,7 @@ COM81.py:577:10: COM812 [*] Trailing comma missing
|
= help: Add trailing comma
Suggested fix
Fix
574 574 | }
575 575 |
576 576 | [
@ -847,7 +847,7 @@ COM81.py:583:10: COM812 [*] Trailing comma missing
|
= help: Add trailing comma
Suggested fix
Fix
580 580 | def foo(
581 581 | ham,
582 582 | spam,
@ -868,7 +868,7 @@ COM81.py:590:13: COM812 [*] Trailing comma missing
|
= help: Add trailing comma
Suggested fix
Fix
587 587 | def foo(
588 588 | ham,
589 589 | spam,
@ -889,7 +889,7 @@ COM81.py:598:15: COM812 [*] Trailing comma missing
|
= help: Add trailing comma
Suggested fix
Fix
595 595 | ham,
596 596 | spam,
597 597 | *args,
@ -909,7 +909,7 @@ COM81.py:627:20: COM812 [*] Trailing comma missing
|
= help: Add trailing comma
Suggested fix
Fix
624 624 | result = function(
625 625 | foo,
626 626 | bar,
@ -929,7 +929,7 @@ COM81.py:632:42: COM812 [*] Trailing comma missing
|
= help: Add trailing comma
Suggested fix
Fix
629 629 |
630 630 | # Make sure the COM812 and UP034 rules don't autofix simultaneously and cause a syntax error.
631 631 | the_first_one = next(