yoastcs icon indicating copy to clipboard operation
yoastcs copied to clipboard

Create a sniff to safeguard that PHPCS annotations aren't being abused

Open jrfnl opened this issue 6 years ago • 1 comments

As previously discussed with @moorscode, this sniff should:

  1. Check that only the new PHPCS annotations are used and forbid use of the old annotations. I.e. the following will no longer be allowed:
    • @codingStandardsIgnoreFile
    • @codingStandardsIgnoreStart / @codingStandardsIgnoreEnd
    • @codingStandardsIgnoreLine
    • @codingStandardsChangeSetting
  2. Detect & forbid blanket PHPCS ignores. The new annotations allow to indicate which Standard/Category/Sniff/Errorcode should be temporarily ignored/disabled.
    • Sniff/Errorcode ignore/disables will be allowed. Errorcode based ones are preferred.
    • Standard/Category ignores/disables will not be allowed.
    • File ignores will not be allowed. These should be done from within the ruleset and documented there.
  3. All temporary disables should be accompanied by a (re-) enable.
  4. All ignores/disables should be accompanied by a reason for the ignore/disable.

This sniff will only be able to work when PHPCS is run with --ignore-annotations as otherwise errors on annotation tokens will be, well, ignored (default behaviour).

This means a secondary PHPCS run will be added to the Travis script if & when this sniff has been added to YoastCS and a plugin upgrades to the YoastCS version which includes it. This secondary run will only check against this particular sniff.

@moorscode In your opinion, does this summarize correctly what we discussed ?

Refs:

  • https://github.com/squizlabs/PHP_CodeSniffer/releases/tag/3.2.0
  • https://github.com/squizlabs/PHP_CodeSniffer/wiki/Advanced-Usage#ignoring-parts-of-a-file

jrfnl avatar Jan 22 '18 22:01 jrfnl