squizlabs / PHP_CodeSniffer

PHP_CodeSniffer tokenizes PHP files and detects violations of a defined set of coding standards.
BSD 3-Clause "New" or "Revised" License
10.63k stars 1.48k forks source link

Don't stop scan on invalid inline property annotation #3916

Closed jrfnl closed 7 months ago

jrfnl commented 8 months ago

Description

Follow up on #3629, which was merged for PHPCS 3.8.0.

PR #3629 added logic to throw a "Ruleset invalid. Property \"$propertyName\" does not exist on sniff ..." error.

This error is intended for the command-line when reading the phpcs.xml.dist ruleset file.

However, this error could also be encountered if an inline // phpcs:set ... annotation would try to set a non-existent property.

While the use of // phpcs:set is typically reserved for sniff test case files, there is nothing stopping end-users from using the annotation.

The net-effect would be:

To me, this is counter-intuitive and counter-productive as it may give people a false sense of security (CI is green, while in reality files are not being scanned).

To fix this, I propose the following:

Includes a test via the Generic.PHP.BacktickOperator sniff.

Suggested changelog entry

I'd suggest updating the existing changelog entry for the change from PR #3629 and adding:

    -- Invalid sniff properties set for sniffs via inline annotations will result in an informative `Internal.PropertyDoesNotExist` errror on line, but will not halt the execution of PHPCS

Types of changes

jrfnl commented 7 months ago

Closing as replaced by https://github.com/PHPCSStandards/PHP_CodeSniffer/pull/99

jrfnl commented 7 months ago

FYI: this fix is included in today's PHP_CodeSniffer 3.8.0 release.

As per #3932, development on PHP_CodeSniffer will continue in the PHPCSStandards/PHP_CodeSniffer repository. If you want to stay informed, you may want to start "watching" that repo (or watching releases from that repo).