Commit 9e8bbfd
committed
PSR2/NamespaceDeclaration: do not enforce new line in inline HTML
If a namespace declaration has a PHP close tag on the same line, the new line would be added as `T_INLINE_HTML` and therefore not be recognized as a blank line as the sniff solely looks for `T_WHITESPACE`. This then leads to a fixer conflict where the sniff just keeps adding new lines until it runs out of loops.
```
=> Fixing file: 0/6 violations remaining [made 46 passes]...
* fixed 0 violations, starting loop 47 *
PSR2.Namespaces.NamespaceDeclaration:81 replaced token 118 (T_INLINE_HTML on line 32) "\n\n" => "\n\n\n"
PSR2.Namespaces.NamespaceDeclaration:81 replaced token 153 (T_INLINE_HTML on line 58) "\n\n" => "\n\n\n"
=> Fixing file: 2/6 violations remaining [made 47 passes]...
* fixed 2 violations, starting loop 48 *
**** PSR2.Namespaces.NamespaceDeclaration:81 has possible conflict with another sniff on loop 46; caused by the following change ****
**** replaced token 118 (T_INLINE_HTML on line 32) "\n\n" => "\n\n\n" ****
**** ignoring all changes until next loop ****
=> Fixing file: 0/6 violations remaining [made 48 passes]...
* fixed 0 violations, starting loop 49 *
```
In my opinion, the sniff should bow out in that situation and should not enforce a new line as it may impact HTML display.
This commit implements this.
Includes a test safeguarding the fix.1 parent 72949bb commit 9e8bbfd
File tree
3 files changed
+19
-0
lines changed- src/Standards/PSR2
- Sniffs/Namespaces
- Tests/Namespaces
3 files changed
+19
-0
lines changedLines changed: 5 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
53 | 58 | | |
54 | 59 | | |
55 | 60 | | |
| |||
Lines changed: 7 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
Lines changed: 7 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
0 commit comments