Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does WPCS do php -l as well? #522

Closed
corysimmons opened this issue Feb 2, 2016 · 8 comments
Closed

Does WPCS do php -l as well? #522

corysimmons opened this issue Feb 2, 2016 · 8 comments

Comments

@corysimmons
Copy link
Contributor

Just curious if it will catch broken PHP as well.

@JDGrimes
Copy link
Contributor

JDGrimes commented Feb 2, 2016

No. PHPCS doesn't explicitly check for syntax errors. There are times when a sniff may detect some tokens that it thinks are invalid, and sometimes the sniff will flag these with an error. But it doesn't intentionally run a syntax check. That's what php -l is for. 😄

https://github.com/squizlabs/PHP_CodeSniffer/wiki/FAQ#does-php_codesniffer-parse-my-code-to-ensure-it-will-execute

@westonruter
Copy link
Member

@corysimmons
Copy link
Contributor Author

Thanks. Out of curiosity, might this be a feature worth considering? Seems like the # 1 rule for WPCS should be "Make sure code is valid". :)

@westonruter
Copy link
Member

Yes, but this would be an issue to introduce upstream in the PHPCS project itself: https://github.com/squizlabs/PHP_CodeSniffer

Nevertheless, since the project specifically calls out the use of php -l, I doubt it would be integrated.

@JDGrimes
Copy link
Contributor

JDGrimes commented Feb 2, 2016

Out of curiosity, might this be a feature worth considering?

It really isn't something that WPCS can do efficiently, because PHPCS doesn't actually parse/execute the code. It would be a lot of work to make a hammer do the job of a screw driver—when we already have a screw driver (php -l) that will do the job just fine.

WPCS is just one tool in your arsenal. The wp-dev-lib repo that @westonruter is a great example of how you can use it along with many others to run a variety of different types of checks on your code. Syntax checking is one check, coding standards is another.

@JDGrimes
Copy link
Contributor

JDGrimes commented Feb 2, 2016

Nevertheless, since the project specifically calls out the use of php -l, I doubt it would be integrated.

IIRC, it has already been suggested on several occasions, and rejected. PHPCS strives not to blow up when handed malformed code, but it doesn't try to catch every syntax error either.

@jrfnl
Copy link
Member

jrfnl commented Jul 14, 2016

FYI: there is actually a sniff upstream available which will run the parser over the file. Not sure how well it works, but could be worth looking into ?

Link: Generic.PHP.SyntaxSniff

@westonruter
Copy link
Member

@jrfnl looks like it is just a wrapper for calling php -l. Probably would be a good thing to add to WordPress-Core.

@westonruter westonruter reopened this Jul 14, 2016
jrfnl added a commit to jrfnl/WordPress-Coding-Standards that referenced this issue Jul 14, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants