Skip to content

Blink: port the fixable slevomat Namespaces sniffs - #410

Merged
TomasVotruba merged 1 commit into
mainfrom
blink-slevomat-namespaces
Nov 20, 2026
Merged

TomasVotruba merged 1 commit into
mainfrom
blink-slevomat-namespaces

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Ports the 13 fixable sniffs of slevomat's Namespaces category to blink, following #402 (PHP).

Sniff Config
AlphabeticallySortedUses psr12Compatible, caseSensitive
FullyQualifiedClassNameInAnnotation ignoredAnnotationNames
FullyQualifiedExceptions specialExceptionNames, ignoredNames
FullyQualifiedGlobalConstants include, exclude
FullyQualifiedGlobalFunctions include, exclude, includeSpecialFunctions
NamespaceDeclaration -
NamespaceSpacing linesCountBeforeNamespace, linesCountAfterNamespace
ReferenceUsedNamesOnly all options
UnusedUses searchAnnotations, ignoredAnnotationNames, ignoredAnnotations
UseDoesNotStartWithBackslash -
UseFromSameNamespace -
UseSpacing linesCountBeforeFirstUse, linesCountBetweenUseTypes, linesCountAfterLastUse
UselessAlias -

Shared layers

  • slevomat_referenced_names.go - port of ReferencedNameHelper (class, function and constant references, in code, strings and attributes).
  • slevomat_phpdoc.go - port of phpstan/phpdoc-parser 2.4.1 (lexer, tag, type and const-expr parsers, format-preserving printer for node swaps) plus AnnotationHelper. Checked against the real parser on 25k docblocks from Laravel, slevomat's tests and generated input: same tags, nodes, spans and printed output.
  • Constant and function existence (defined() / function_exists() upstream) uses embedded lists for the bundled extensions, so a name from an optional extension like curl counts as undefined in blink.

Tests

  • 184 new golden cases from the upstream fixtures, generated by ECS. Data-provider parameters are expanded into p1/p2 variants.
  • Where upstream's .fixed.php differs from ECS: 3 tests restrict the sniff to some error codes (ECS always runs all of it), and ECS fixes only one annotation per docblock per pass (each fix rewrites the whole docblock from the parse taken at the start of the pass) and stops when a pass makes no change, where phpcbf keeps going.
  • On 6 of those fixtures a second ECS run changes the output again; they carry "unstable": true, which skips the stability check. Blink's second run equals ECS's second run on each.

Shim

  • slvRun gives up after 100 loops (ECS's MAX_FIXER_LOOPS) and keeps the file unchanged, like ECS. It used to stop at 50 and keep the last output.
  • true/false/null followed by ( or :: are names, and \true/\false/\null/\exit/\die are not, as in PHP_CodeSniffer's tokenizer. Arrays, Functions, Operators, Attributes and PHP were re-checked against ECS with both changes, with no difference.

Parity with ECS

Every sniff was run by ECS and by blink on Laravel src, clean and with mutations targeting it (shuffled, aliased, group, function and const uses, blank lines around namespaces and uses, fully qualified names in code and docblocks, colliding names, partial uses, files without namespace, annotations of every tag shape), with default and non-default configs. Output is byte-identical everywhere. The only exception is ReferenceUsedNamesOnly with fallback global functions/constants disallowed, where ECS also imports functions from the extensions loaded on the machine running it.

Ports AlphabeticallySortedUses, FullyQualifiedClassNameInAnnotation,
FullyQualifiedExceptions, FullyQualifiedGlobalConstants,
FullyQualifiedGlobalFunctions, NamespaceDeclaration, NamespaceSpacing,
ReferenceUsedNamesOnly, UnusedUses, UseDoesNotStartWithBackslash,
UseFromSameNamespace, UseSpacing and UselessAlias, with ports of
ReferencedNameHelper and the phpdoc-parser annotation layer they share.

The shim gives up on a file whose fixes never settle after 100 loops and
keeps it unchanged, like ECS, and true/false/null followed by ( or :: are
names, like in PHP_CodeSniffer's tokenizer.
@TomasVotruba
TomasVotruba force-pushed the blink-slevomat-namespaces branch from cacf580 to 6088e55 Compare November 19, 2026 23:36
@TomasVotruba
TomasVotruba merged commit 9d8a68b into main Nov 20, 2026
12 checks passed
@TomasVotruba
TomasVotruba deleted the blink-slevomat-namespaces branch November 20, 2026 09:01
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