Skip to content

Blink: port 21 PSR2, PSR12 and PEAR PHP_CodeSniffer sniffs - #405

Merged
TomasVotruba merged 8 commits into
mainfrom
blink-phpcs-psr-pear
Nov 19, 2026
Merged

TomasVotruba merged 8 commits into
mainfrom
blink-phpcs-psr-pear

Conversation

@TomasVotruba

@TomasVotruba TomasVotruba commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

Ports 21 more fixable PHP_CodeSniffer sniffs to blink. PHP_CodeSniffer coverage goes from 65/114 to 86/114.

Each matches ECS output byte for byte on the upstream PHPCS 4.0.4 test inputs (TestPhpcsUpstreamFixtures).

  • PEAR: ClassDeclaration, FunctionComment, MultiLineCondition, ScopeClosingBrace, ObjectOperatorIndent, FunctionCallSignature, FunctionDeclaration, IncludingFile
  • PSR2: ClassDeclaration, Namespaces UseDeclaration, PropertyDeclaration, MethodDeclaration, ControlStructureSpacing, SwitchDeclaration
  • PSR12: AnonClassDeclaration, DeclareStatement, FileHeader, Traits UseDeclaration, ControlStructureSpacing, BooleanOperatorPlacement

Shared changes:

  • phpcs_scope.go - port of PHPCS's scope map (scope owners, case/default shared closers, alternative syntax) plus findStartOfStatement/findEndOfStatement; checked token for token against the PHPCS tokenizer. Also the base ScopeIndent needs.
  • slevomat.go - brackets matched with one stack per type like PHPCS, tabs expanded in inline HTML, \true/\false/\null counted at their known length, interpolated string pieces marked. Slevomat ports still pass.
  • phpcsClassyOpener - applies the PHPCS anonymous-class rule without a preceding new.
  • TestPhpcsUpstreamFixtures - a sniff with phpcsOnePass() is fixed only once, matching where ECS stops on the PSR2 ClassDeclaration extends/implements conflict.
  • TestOperatorLinebreakKeepsNullFirstParenAssignment runs every rule, so its expected output now has the multi-line if closing ) on its own line (PSR12 ControlStructureSpacing).

Known difference: PEAR FunctionCallSignature re-indents a heredoc closing marker like PHPCS does, which can produce invalid PHP. ECS writes it; blink's post-fix php -l reverts the file.

bin/phpcs-fixtures.sh now runs ECS once per input file - PHPCS's fixer carries conflict history across files in one ECS run, which left some inputs half-fixed. All existing fixtures regenerate byte-identical.

Still left outside Squiz: Generic ScopeIndent.

…lassInstantiation and PSR12 Traits UseDeclaration sniffs
…atorPlacement and PEAR MultiLineCondition sniffs
…bjectOperatorIndent sniffs

Adds a port of PHP_CodeSniffer's scope map (recurseScopeMap, the CASE/DEFAULT
and arrow function fixes of processAdditional), findStartOfStatement and
findEndOfStatement on the slvFile shim. It matches PHP_CodeSniffer's own
scope_condition/opener/closer on every upstream test input but one short open
tag file. The shim now also expands tabs in inline HTML and counts a fully
qualified true/false/null at PHP_CodeSniffer's known length, as its tokenizer
does.
…eader and PSR2 UseDeclaration sniffs

phpcs-fixtures.sh now runs ECS once per input file: PHP_CodeSniffer's fixer keeps conflict state from file to file, so a multi-file run left some inputs half-fixed.
@TomasVotruba TomasVotruba changed the title Blink: port 17 PSR2, PSR12 and PEAR PHP_CodeSniffer sniffs Blink: port 21 PSR2, PSR12 and PEAR PHP_CodeSniffer sniffs Nov 19, 2026
@TomasVotruba
TomasVotruba merged commit f9961b0 into main Nov 19, 2026
12 checks passed
@TomasVotruba
TomasVotruba deleted the blink-phpcs-psr-pear branch November 19, 2026 21:56
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