Skip to content

Commit

Permalink
Merge branch 'cleanup'
Browse files Browse the repository at this point in the history
  • Loading branch information
lkrms committed Nov 25, 2024
2 parents f6fda77 + 75cb5d1 commit c021dbf
Show file tree
Hide file tree
Showing 40 changed files with 548 additions and 825 deletions.
23 changes: 10 additions & 13 deletions .vscode/php.code-snippets
Original file line number Diff line number Diff line change
Expand Up @@ -99,20 +99,17 @@
},
"Return priority": {
"scope": "php",
"prefix": "switch",
"prefix": "return",
"body": [
"switch (\\$method) {",
" case self::PROCESS_TOKENS:",
" case self::PROCESS_LIST:",
" case self::PROCESS_BLOCK:",
" return null;",
"",
" case self::BEFORE_RENDER:",
" return null;",
"",
" default:",
" return null;",
"}",
"return [",
" self::PROCESS_TOKENS => null,",
" self::PROCESS_STATEMENTS => null,",
" self::PROCESS_DECLARATIONS => null,",
" self::PROCESS_LIST => null,",
" self::PROCESS_BLOCK => null,",
" self::CALLBACK => null,",
" self::BEFORE_RENDER => null,",
"][\\$method] ?? null;",
]
},
"Namespace": {
Expand Down
80 changes: 43 additions & 37 deletions docs/Rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ needed.

### `ProtectStrings`

Whitespace is suppressed via critical masks applied to siblings in non-constant
strings, and to every token between square brackets in those strings.
Changes to whitespace in non-constant strings are suppressed for:

- nested siblings
- every descendant of square brackets that are nested siblings

### `SimplifyNumbers`

Expand All @@ -75,26 +77,24 @@ Float literals are normalised by removing redundant zeroes, adding `0` to empty
integer or fractional parts, replacing `E` with `e`, removing `+` from
exponents, and expressing them with mantissae between 1.0 and 10.

If present in the input, underscores are added to decimal values with no
If present in the input, underscores are applied to decimal values with no
exponent every 3 digits, to hexadecimal values with more than 5 digits every 4
digits, and to binary values every 4 digits.

### `SimplifyStrings`

Strings other than nowdocs are normalised as follows:

Single- and double-quoted strings are replaced with the most readable and
economical syntax. Single-quoted strings are preferred unless escaping is
required or the double-quoted equivalent is shorter.

Backslash escapes are added in contexts where they improve safety, consistency
and readability, otherwise they are removed if possible.

Aside from leading and continuation bytes in valid UTF-8 strings, control
characters and non-ASCII characters are backslash-escaped using hexadecimal
notation with lowercase digits. Invisible characters that don't belong to a
recognised Unicode sequence are backslash-escaped using Unicode notation with
uppercase digits.
- Single- and double-quoted strings are replaced with the most readable and
economical syntax. Single-quoted strings are preferred unless escaping is
required or the double-quoted equivalent is shorter.
- Backslash escapes are added in contexts where they improve safety, consistency
and readability, otherwise they are removed if possible.
- Aside from leading and continuation bytes in valid UTF-8 strings, control
characters and non-ASCII characters are backslash-escaped using hexadecimal
notation with lowercase digits. Invisible characters that don't belong to a
recognised Unicode sequence are backslash-escaped using Unicode notation with
uppercase digits.

### `NormaliseComments`

Expand Down Expand Up @@ -181,12 +181,13 @@ Whitespace is applied to structural and `match` expression braces as follows:
- Newlines are added after close braces unless they belong to a `match`
expression or a control structure that is immediately continued, e.g.
`} else {`. In the latter case, trailing newlines are suppressed.
- Empty class, function and property hook bodies are collapsed to ` {}`
immediately after the declaration they belong to.
- Empty class, function and property hook bodies are collapsed to ` {}` on the
same line as the declaration they belong to unless
`CollapseEmptyDeclarationBodies` is disabled.
- Horizontal whitespace is suppressed between other empty braces.

Open brace placement is left for a rule that runs after vertical whitespace has
been applied.
> Open brace placement is left for a rule that runs after vertical whitespace
> has been applied.
### `ListSpacing` (call 1: `processDeclarations()`)

Expand All @@ -206,6 +207,11 @@ annotated parameters to improve readability.
If interface lists break over multiple lines and neither `StrictLists` nor
`AlignLists` are enabled, a newline is added before the first interface.

### `StrictLists`

Items in lists are arranged horizontally or vertically by replicating the
arrangement of the first and second items.

### `StandardWhitespace` (call 3: _`callback`_)

The `TagIndent` of tokens between indented tags is adjusted by the difference,
Expand Down Expand Up @@ -284,23 +290,23 @@ lines, they are collapsed to the same line.

## `DeclarationRule` classes, by declaration type

| Declaration | Rules |
| -------------- | ----------------------------------- |
| `*` | `StandardWhitespace` |
| `CASE` | `DeclarationSpacing` |
| `CLASS` | `DeclarationSpacing` |
| `CONST` | `DeclarationSpacing` |
| `DECLARE` | `DeclarationSpacing` |
| `ENUM` | `DeclarationSpacing` |
| `FUNCTION` | `DeclarationSpacing` |
| `INTERFACE` | `DeclarationSpacing` |
| `NAMESPACE` | `DeclarationSpacing` |
| `PARAM` | `ListSpacing` |
| `PROPERTY` | `DeclarationSpacing`, `ListSpacing` |
| `TRAIT` | `DeclarationSpacing` |
| `USE_CONST` | `DeclarationSpacing` |
| `USE_FUNCTION` | `DeclarationSpacing` |
| `USE_TRAIT` | `DeclarationSpacing` |
| `USE` | `DeclarationSpacing` |
| Declaration | Rules |
| -------------- | --------------------------------------------------------- |
| `CASE` | `DeclarationSpacing` |
| `CLASS` | `DeclarationSpacing` |
| `CONST` | `DeclarationSpacing` |
| `DECLARE` | `DeclarationSpacing` |
| `ENUM` | `DeclarationSpacing` |
| `FUNCTION` | `DeclarationSpacing` |
| `HOOK` | `DeclarationSpacing` |
| `INTERFACE` | `DeclarationSpacing` |
| `NAMESPACE` | `DeclarationSpacing` |
| `PARAM` | `ListSpacing`, `StandardWhitespace` |
| `PROPERTY` | `DeclarationSpacing`, `ListSpacing`, `StandardWhitespace` |
| `TRAIT` | `DeclarationSpacing` |
| `USE_CONST` | `DeclarationSpacing` |
| `USE_FUNCTION` | `DeclarationSpacing` |
| `USE_TRAIT` | `DeclarationSpacing` |
| `USE` | `DeclarationSpacing` |

[list-rules.php]: ../scripts/list-rules.php
108 changes: 0 additions & 108 deletions phpstan-baseline-7.4.neon
Original file line number Diff line number Diff line change
Expand Up @@ -24,36 +24,6 @@ parameters:
count: 1
path: src/Formatter.php

-
message: '#^Cannot access property \$CriticalWhitespaceMaskNext on Lkrms\\PrettyPHP\\Token\|null\.$#'
identifier: property.nonObject
count: 1
path: src/Internal/TokenCollection.php

-
message: '#^Cannot access property \$CriticalWhitespaceMaskPrev on Lkrms\\PrettyPHP\\Token\|null\.$#'
identifier: property.nonObject
count: 1
path: src/Internal/TokenCollection.php

-
message: '#^Cannot access property \$WhitespaceMaskNext on Lkrms\\PrettyPHP\\Token\|null\.$#'
identifier: property.nonObject
count: 1
path: src/Internal/TokenCollection.php

-
message: '#^Cannot access property \$WhitespaceMaskPrev on Lkrms\\PrettyPHP\\Token\|null\.$#'
identifier: property.nonObject
count: 1
path: src/Internal/TokenCollection.php

-
message: '#^Cannot call method collect\(\) on Lkrms\\PrettyPHP\\Token\|null\.$#'
identifier: method.nonObject
count: 2
path: src/Internal/TokenCollection.php

-
message: '#^Parameter \#1 \$to of method Lkrms\\PrettyPHP\\Token\:\:collect\(\) expects Lkrms\\PrettyPHP\\Token, Lkrms\\PrettyPHP\\Token\|null given\.$#'
identifier: argument.type
Expand Down Expand Up @@ -150,12 +120,6 @@ parameters:
count: 1
path: src/Rule/ControlStructureSpacing.php

-
message: '#^Cannot access property \$WhitespaceMaskNext on Lkrms\\PrettyPHP\\Token\|null\.$#'
identifier: property.nonObject
count: 2
path: src/Rule/ControlStructureSpacing.php

-
message: '#^Cannot access property \$LinePadding on Lkrms\\PrettyPHP\\Token\|null\.$#'
identifier: property.nonObject
Expand All @@ -174,12 +138,6 @@ parameters:
count: 2
path: src/Rule/HeredocIndentation.php

-
message: '#^Cannot access property \$WhitespaceMaskNext on Lkrms\\PrettyPHP\\Token\|null\.$#'
identifier: property.nonObject
count: 1
path: src/Rule/PlaceComments.php

-
message: '#^Cannot call method collect\(\) on Lkrms\\PrettyPHP\\Token\|null\.$#'
identifier: method.nonObject
Expand All @@ -192,74 +150,8 @@ parameters:
count: 1
path: src/Rule/PreserveNewlines.php

-
message: '#^Cannot access property \$WhitespaceMaskPrev on Lkrms\\PrettyPHP\\Token\|null\.$#'
identifier: property.nonObject
count: 1
path: src/Rule/StatementSpacing.php

-
message: '#^Cannot access property \$id on Lkrms\\PrettyPHP\\Token\|null\.$#'
identifier: property.nonObject
count: 3
path: src/Rule/StatementSpacing.php

-
message: '#^Cannot access property \$ClosedBy on Lkrms\\PrettyPHP\\Token\|null\.$#'
identifier: property.nonObject
count: 1
path: src/Rule/StrictExpressions.php

-
message: '#^Cannot access property \$NextCode on Lkrms\\PrettyPHP\\Token\|null\.$#'
identifier: property.nonObject
count: 1
path: src/Rule/StrictExpressions.php

-
message: '#^Cannot access property \$PrevCode on Lkrms\\PrettyPHP\\Token\|null\.$#'
identifier: property.nonObject
count: 1
path: src/Rule/StrictExpressions.php

-
message: '#^Cannot access property \$WhitespaceAfter on Lkrms\\PrettyPHP\\Token\|null\.$#'
identifier: property.nonObject
count: 1
path: src/Rule/StrictExpressions.php

-
message: '#^Cannot access property \$WhitespaceBefore on Lkrms\\PrettyPHP\\Token\|null\.$#'
identifier: property.nonObject
count: 1
path: src/Rule/StrictExpressions.php

-
message: '#^Cannot access property \$WhitespaceMaskNext on Lkrms\\PrettyPHP\\Token\|null\.$#'
identifier: property.nonObject
count: 2
path: src/Rule/StrictExpressions.php

-
message: '#^Cannot access property \$WhitespaceMaskPrev on Lkrms\\PrettyPHP\\Token\|null\.$#'
identifier: property.nonObject
count: 2
path: src/Rule/StrictExpressions.php

-
message: '#^Cannot call method collect\(\) on Lkrms\\PrettyPHP\\Token\|null\.$#'
identifier: method.nonObject
count: 1
path: src/Rule/StrictExpressions.php

-
message: '#^Cannot call method hasNewlineAfter\(\) on Lkrms\\PrettyPHP\\Token\|null\.$#'
identifier: method.nonObject
count: 1
path: src/Rule/StrictExpressions.php

-
message: '#^Cannot call method hasNewlineBefore\(\) on Lkrms\\PrettyPHP\\Token\|null\.$#'
identifier: method.nonObject
count: 1
path: src/Rule/StrictLists.php
Loading

0 comments on commit c021dbf

Please sign in to comment.