Skip to content

Blink: port the fixable slevomat PHP sniffs - #402

Merged
TomasVotruba merged 1 commit into
mainfrom
blink-slevomat-php
Nov 19, 2026
Merged

TomasVotruba merged 1 commit into
mainfrom
blink-slevomat-php

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Ports the 9 fixable sniffs of slevomat's PHP category to blink, following #400 (Attributes).

Sniff Config
DisallowDirectMagicInvokeCall -
ForbiddenClasses forbiddenClasses, forbiddenExtends, forbiddenInterfaces, forbiddenTraits
ReferenceSpacing spacesCountAfterReference
RequireExplicitAssertion enableIntegerRanges, enableAdvancedStringTypes
RequireNowdoc -
ShortList -
TypeCast -
UselessParentheses ignoreComplexTernaryConditions, enableCheckAroundNew
UselessSemicolon -

Tests

  • 27 new golden cases from the upstream fixtures, generated by ECS running the real sniff, checked byte-exact with an idempotency check. All 13 PHP goldens equal upstream's own .fixed.php.
  • Two inputs upstream runs under two configs get variant names (forbiddenClasses.configured, uselessParenthesesCheckAroundNewErrors.enabled/disabled).
  • The fixture test now fails a case cleanly instead of panicking when a configured sniff takes no configuration.

Shim

  • braceOwner no longer reaches past a closed block, ->, ::, = or a variable. Before, the { of $this->{$x} was taken for the scope of an earlier if. Arrays, Functions, Operators and Attributes were re-checked against ECS with this change, with no difference.
  • scopeCondition adds PHP_CodeSniffer's scope_condition for trait use blocks (use T { ... }), used by UselessSemicolon and ForbiddenClasses.
  • RequireExplicitAssertion carries a hand-written parser for the phpdoc types it can assert (names, $this, int<a, b>, flat unions and intersections, parentheses); anything else is skipped, as upstream does when it cannot build an assertion.

Parity with ECS

Every sniff (non-default configs too) was run by ECS and by blink on Laravel src, clean and with mutations targeting it (->__invoke(, & $x, list(...), long cast names, doubled ;;, };, heredocs from nowdocs, added parentheses, @var annotations of many shapes, forbidden classes, traits and interfaces). Output is byte-identical everywhere, except files where upstream produces invalid PHP, which blink's lint guard reverts: RequireNowdoc (1), UselessParentheses with enableCheckAroundNew (2, new ($expr)->x), RequireExplicitAssertion (1, an \assert in a class body). Without the lint guard blink's output equals ECS there too.

ECS aborts a file when RequireExplicitAssertion meets an annotated constructor parameter with a default value (upstream TypeError); blink leaves such a file unchanged the same way.

Ports DisallowDirectMagicInvokeCall, ForbiddenClasses, ReferenceSpacing,
RequireExplicitAssertion, RequireNowdoc, ShortList, TypeCast,
UselessParentheses and UselessSemicolon, verified on golden outputs generated
by ECS from the upstream test fixtures.

The shim's braceOwner no longer reaches past a closed block, an object
operator or an assignment, so $this->{$x} is not taken for a scope, and it
gains PHP_CodeSniffer's scope_condition for trait use blocks.
@TomasVotruba
TomasVotruba enabled auto-merge (squash) November 19, 2026 21:18
@TomasVotruba
TomasVotruba merged commit 6c585f1 into main Nov 19, 2026
12 checks passed
@TomasVotruba
TomasVotruba deleted the blink-slevomat-php branch November 19, 2026 21:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant