Skip to content

Support for psalm/phpstan/phan PHPDoc tags #22

@shadowwa

Description

@shadowwa

In the syntax file, there is a support for phpDocCustomTags but only for tag like @[a-zA-Z]* without dash character.

psalm, phpstan and phan use custom tags prefixed by the name of the program separated with a dash, the tag can even have several dash like:

/**
 * @phpstan-return
 * @phpstan-template-covariant
 * @phan-param
 * @psalm-var
 * @psalm-ignore-variable-property
 */

I have a ~/.vim/syntax/php.vim file containing

syntax match phpDocPhpstanTags "@phpstan-\(import-type\|assert-if-false\|assert-if-true\|assert\|extends\|implements\|import-type\|impure\|method\|param-closure-this\|param-immediately-invoked-callable\|param-later-invoked-callable\|param-out\|param\|property-read\|property-write\|property\|require-extends\|require-implements\|return\|self-out\|template-contravariant\|template-covariant\|template\|this-out\|throws\|type\|use\|var\)\(\s\+\|\n\|\r\)" containedin=phpComment
syntax match phpDocPhpstanIgnoreTags "@phpstan-\(ignore\|ignore-line\|ignore-next-line\)\(\s\+\|\n\|\r\)" containedin=phpComment

syntax match phpDocPhanTags "@phan-\(param\|assert-if-false\|assert-if-true\|assert\|extends\|inherits\|method\|mixin\|property-read\|property-write\|property\|real-return\|return\|template\|type\|var\)\(\s\+\|\n\|\r\)" containedin=phpComment

syntax match phpDocPsalmTags "@psalm-\(allow-private-mutation\|api\|assert\|assert-if-false\|assert-if-true\|check-type\|check-type-exact\|consistent-constructor\|consistent-templates\|external-mutation-free\|if-this-is\|immutable\|import-type\|inheritors\|internal\|method\|mutation-free\|no-seal-methods\|no-seal-properties\|param\|param-out\|property\|property-read\|property-write\|pure\|readonly\|readonly-allow-private-mutation\|require-extends\|require-implements\|return\|seal-methods\|seal-properties\|this-out\|trace\|type\|var\|yield\)\(\s\+\|\n\|\r\)" containedin=phpComment
syntax match phpDocPsalmTags "@psalm-taint-\(source\|sink\|escape\|unescape\|specialize\)\(\s\+\|\n\|\r\)" containedin=phpComment
syntax match phpDocPsalmTags "@\(param-out\|no-named-arguments\|no-seal-methods\|no-seal-properties\|seal-methods\|seal-properties\)\(\s\+\|\n\|\r\)" containedin=phpComment
syntax match phpDocPsalmIgnoreTags "@psalm-\(ignore-falsable-return\|ignore-nullable-return\|ignore-var\|ignore-variable-method\|ignore-variable-property\|suppress\)\(\s\+\|\n\|\r\)" containedin=phpComment

hi def link phpDocPhpstanTags phpDocCustomTags
hi def link phpDocPhpstanIgnoreTags Exception
hi def link phpDocPhanTags phpDocCustomTags
hi def link phpDocPsalmTags phpDocCustomTags
hi def link phpDocPsalmIgnoreTags Exception

do you think these could be added in your syntax file or do you prefer not mix "official" phpdoc tags and tags created by static analyzer?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions