Commit 6d61496
committed
Squiz/SwitchDeclaration: make implied semicolon via close tag auto-fixable
The `Squiz.ControlStructures.SwitchDeclaration` sniff does _not_ include a rule/error for the scope opener not being a `:` colon, though all the error messages have the presumption of the scope opener being a colon in the textual content.
The sniff does have tests with a semicolon scope opener and as there is no error related to the semicolon being a scope opener, I can only presume that it was previously decided to allow that in the Squiz standard.
Considering that this is a code style sniff, it is not for this sniff to enforce PHP cross-version compatibility of code, so the PHP 8.5 deprecation is irrelevant and there is no reason to change the behaviour of the sniff for semicolon scope openers.
However, the sniff definitely did not function correctly for code moving in and out of PHP within a `switch` statement.
PR 1315 was a first step towards supporting this.
This commit now adds a new error to disallow a PHP close tag as the "scope_opener" for `case`/`default` statements.
The error is auto-fixable and will insert a colon before the PHP close tag as the fix.
With this additional error in place, the sniff's handling of code within a `switch` moving in and out of PHP has greatly improved.
Includes tests.1 parent 21c0e80 commit 6d61496
File tree
4 files changed
+67
-0
lines changed- src/Standards/Squiz
- Sniffs/ControlStructures
- Tests/ControlStructures
4 files changed
+67
-0
lines changedLines changed: 13 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
141 | 141 | | |
142 | 142 | | |
143 | 143 | | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
144 | 157 | | |
145 | 158 | | |
146 | 159 | | |
| |||
Lines changed: 16 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
380 | 380 | | |
381 | 381 | | |
382 | 382 | | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
Lines changed: 30 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
404 | 404 | | |
405 | 405 | | |
406 | 406 | | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
Lines changed: 8 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
91 | 99 | | |
92 | 100 | | |
93 | 101 | | |
| |||
0 commit comments