WPTT / WPThemeReview

PHP_CodeSniffer rules (sniffs) to enforce WordPress theme review coding conventions
MIT License
208 stars 38 forks source link

Prohibit the use of the PHP `goto` language construct #154

Closed jrfnl closed 6 years ago

jrfnl commented 6 years ago

While goto is rarely - if ever - used in themes, it also shouldn't be.

This sniff will safeguard against its use.

dingo-d commented 6 years ago

After I commented out the WordPress.Theme.CorrectTGMPAVersions rule (I guess it's not merged yet in this branch) the sniff worked fine - it detected goto and the line where goto should go, so it's OK to merge :)

jrfnl commented 6 years ago

After I commented out the WordPress.Theme.CorrectTGMPAVersions rule (I guess it's not merged yet in this branch) the sniff worked fine - it detected goto and the line where goto should go, so it's OK to merge :)

Could you expand on that a little more ? This branch already contains that sniff, so commenting it out shouldn't be needed.

Oh and a pro-tip: if you just want to test one particular sniff (or only a few), you can run PHPCS like so: phpcs ./file-you-want-to-test.php --standard=WordPress-Theme --sniffs=WordPress.PHP.DiscourageGoto

dingo-d commented 6 years ago

I cloned this fork in my wpcs folder where my sniffs are, and when I went to write a sample code in Sublime (with the WordPress-Theme as the standard), I got the error

ERROR: Referenced sniff "WordPress.Theme.CorrectTGMPAVersions" does not exist

I tested it with WordPress standard and everything worked (goto showed error).

jrfnl commented 6 years ago

@dingo-d Ah, ok. I'm not familiar enough with Sublime, but this feels like it might be using a different version than your clone - maybe even a cached version ?

Could you check by running PHPCS from the command-line over your test code ? If you don't get the error when you do that, the problem is with Sublime, not with the repo.

dingo-d commented 6 years ago

Did that and ran it from the terminal and got ERROR: Referenced sniff "WordPress.Theme.CorrectTGMPAVersions" does not exist.

When I do it with

phpcs testgoto.php --standard=WordPress --sniffs=WordPress.PHP.DiscourageGoto

I get the correct error 3 | ERROR | The "goto" language construct should not be used.

The test file looks like:

<?php

goto a;

a;

I'll try to delete and pull the clean repo and see if I can reproduce it.

EDIT: Nope still got the same error after a clean install...

jrfnl commented 6 years ago

@dingo-d Thanks for testing! Found it now. Looks like I made typo/change the sniffname and forgot to change it in the ruleset. PR #156 should fix it.

dingo-d commented 6 years ago

Great, you can merge it then :) :+1: