slevomat / coding-standard

Slevomat Coding Standard for PHP_CodeSniffer provides many useful sniffs
MIT License
1.37k stars 170 forks source link

TypeHints.UnionTypeHintFormat seems to crash #1664

Closed ghnp5 closed 4 months ago

ghnp5 commented 4 months ago

If I enable this sniff:

    <rule ref="SlevomatCodingStandard.TypeHints.UnionTypeHintFormat">
        <properties>
            <property name="enable" value="yes"/>
            <property name="shortNullable" value="yes"/>
        </properties>
    </rule>

I get this crash:

2024-02-16 07:38:35.992 [error] Error: { "vscodeOptions": { "tabWidth": 1 }, "result": PHP Fatal error: Uncaught TypeError: SlevomatCodingStandard\Helpers\SniffSettingsHelper::isEnabledByPhpVersion(): Argument #1 ($value) must be of type ?bool, string given, called in F:\xxx\vendor\slevomat\coding-standard\SlevomatCodingStandard\Sniffs\TypeHints\UnionTypeHintFormatSniff.php on line 70 and defined in F:\xxx\vendor\slevomat\coding-standard\SlevomatCodingStandard\Helpers\SniffSettingsHelper.php:80 Stack trace:

0 F:\xxx\vendor\slevomat\coding-standard\SlevomatCodingStandard\Sniffs\TypeHints\UnionTypeHintFormatSniff.php(70): SlevomatCodingStandard\Helpers\SniffSettingsHelper::isEnabledByPhpVersion()

1 F:\xxx\vendor\squizlabs\php_codesniffer\src\Files\File.php(518): SlevomatCodingStandard\Sniffs\TypeHints\UnionTypeHintFormatSniff->process()

2 F:\xxx\vendor\squizlabs\php_codesniffer\src\Runner.php(632): PHP_CodeSniffer\Files\File->process()

3 F:\xxx\vendor\squizlabs\php_codesniffer\src\Runner.php(438): PHP_CodeSniffer\Runner->processFile()

4 F:\xxx\vendor\squizlabs\php_codesniffer\src\Runner.php(116): PHP_CodeSniffer\Runner->run()

5 F:\xxx\vendor\squizlabs\php_codesniffer\bin\phpcs(18): PHP_CodeSniffer\Runner->runPHPCS()

6 F:\xxx\vendor\bin\phpcs(119): include('...')

7 {main}

thrown in F:\xxx\vendor\slevomat\coding-standard\SlevomatCodingStandard\Helpers\SniffSettingsHelper.php on line 80

at executeCommand (c:\Users\xxx.vscode\extensions\wongjn.php-sniffer-1.3.0\lib\cli.js:151:29) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async Object.phpcs (c:\Users\xxx.vscode\extensions\wongjn.php-sniffer-1.3.0\lib\runner.js:159:22)

Thank you.

kukulich commented 4 months ago

value="yes" is not valid value for boolean options.

ghnp5 commented 4 months ago

value="yes" is not valid value for boolean options.

What should be the value, then? It's not clear in the documentation, and you're not being clear here either.

enable: either to enable or not this sniff. By default, it is enabled for PHP versions 8.0 or higher.

ghnp5 commented 4 months ago

Thank you very much for the answer 👍🏼