JsLint for PHP anyone?

By | | PHP

9

Anyone with excess time and skill on their hands? Would be awesome to see a port of jslint to PHP (and Perl / Python / Ruby for that matter). There’s probably some issues with multibyte strings to contend with but browsing the source it looks doable.

It would mean is tools like Simple Test could help validate Javascript on a page they’re. Simple Test comes with it’s own regex-based parsing tools, which I introduced briefly here. Whether regexes are the right way to go though is another question, bearing in mind character encoding issues.

Written By:

Harry Fuecks

Harry has been working in corporate IT since 1994, with everything from start-ups to Fortune 100 companies. Outside of office hours he runs phpPatterns: a site dedicated to software design with PHP that aims to raise standards of PHP development. He also maintains Dynamically Typed: SitePoint's PHP blog.

 

{ 9 comments }

Danno July 25, 2008 at 6:26 pm

The php -l is also buggy.
For example if you have:

It will return that the syntax is ok. But when you execute that you get the error.

Azmo October 8, 2004 at 8:20 am

php_check_syntax still has a bug, though. It executes the code as well as checking it, so any errors will still… cause errors.

HarryF October 7, 2004 at 3:20 am

There’s a new function in PHP: php_check_syntax.

mrsmiley October 6, 2004 at 7:34 pm

I was refering to the jslint port, not the uberlint I hinted at before.

mrsmiley October 6, 2004 at 7:33 pm

I’m willing to give it a go when I find some spare time. Good chance for me to finally look at some of the strange OO syntax for JS in a bit more detail.

mrsmiley October 6, 2004 at 7:16 pm

Why would you want to go to the trouble of creating a checker for PHP? PHP comes with a syntax checker built in…

php -l filename.php

(that’s a lowercase L by the way). The CLI version has a lint command built into it. If you want to create a web based interface for something like SimpleTest, all you need to do is run it as a system command to check for errors.

A multi-language lint would be better. Seeing as php scripts can contain js, php, html, xml, etc, you’d really want the lint check to be able to detect which language it is parsing at the time. I think I’ll just chuck that idea in the too hard basket though.

Davey October 6, 2004 at 6:55 pm

Okay, JavaScript. But it would be even cooler to have a lint-y thing for PHP, like pychecker for Python, http://pychecker.sourceforge.net/

Anyone up to it, or is there already such a thing?

Since PHP4, there has been the -l (thats a lower case L) flag for the PHP binary, L standing for Lint, it’ll find parse errors.

In PHP5, there is the nice userland function php_check_syntax() [http://www.php.net/manual/en/function.php-check-syntax.php]

- Davey

someonewhois October 6, 2004 at 6:37 pm

Kinda cool.. wouldn’t be easy to do.

SB October 6, 2004 at 1:59 pm

Okay, JavaScript. But it would be even cooler to have a lint-y thing for PHP, like pychecker for Python, http://pychecker.sourceforge.net/

Anyone up to it, or is there already such a thing?

Comments on this entry are closed.