WordPress-Coding-Standards icon indicating copy to clipboard operation
WordPress-Coding-Standards copied to clipboard

Task: make sure all sniffs are triggered via `class-ruleset-test.php`

Open jrfnl opened this issue 7 years ago • 1 comments

The /bin/class-ruleset-test.php file is used to test the WPCS rulesets.

This file should contain code which triggers each and every sniff in the WPCS rulesets but should not trigger any errors! This way the file can be used to check that there are no typos in sniff names or other ruleset issues.

As of July 24th 2018:

  • All WPCS native sniffs were covered.
  • All (PHPCS) sniffs used in the WordPress-Core ruleset were covered by this file.

Tasks:

  • [ ] Verify that all new WPCS native sniffs introduced since July 2018 are triggered by this sniff.
  • [ ] Verify that any new PHPCS sniffs added to the WordPress-Core ruleset are triggered by this file.
  • [ ] Verify that all PHPCS sniffs included in the WordPress-Extra ruleset are triggered by this file and add additional code samples for those sniffs currently not (yet) triggered.
  • [ ] Verify that all PHPCS sniffs included in the WordPress-Docs ruleset are triggered by this file and add additional code samples for those sniffs currently not (yet) triggered.

To do this you need to take the following steps for each sniff:

  • Open the relevant sniff file.
  • Check what tokens are being registered by the sniff and verify that one or more of those tokens exist in the test file.
  • Check what errors the sniff throws and make sure the code in the test case file using those tokens is "clean", i.e. would not throw those errors, but does trigger the sniff. The easiest way to test this is to make the code "dirty", verify that the expected error(s) are being thrown and then clean it up again.
  • If a token is not included in the test file, a PHP code sample without parse errors which contains the token should be added to the sniff. Similarly to the above bullet, the code should first be added as "dirty" to verify that the sniff is triggered and then be cleaned up before committing.
  • If adding a token - such as the T_GOTO token - would always trigger an error, the PHPCS 3.2+ whitelist annotations can be used to silence those (see examples in the file).

jrfnl avatar Dec 16 '18 15:12 jrfnl

I'd say either someone needs to update the test files soonish or else, let's remove those tests as without them covering all the sniffs, it's kind of useless to have them.

jrfnl avatar Dec 09 '22 16:12 jrfnl