Closed westonruter closed 6 years ago
For a server-side PHP linter, see https://github.com/WordPress/better-code-editing/pull/3/commits/1ff1bceaaec8531d72689f1c40b69a89d20f5cd8
This had to be revered because the approach will not work on many hosts due to security restrictions.
We could possibly implement a lightweight linter in PHP that uses CodeMirror's tokenizer to do brace matching.
Props to @rheinardkorf for finding http://glayzzle.com/php-parser/#demo !!
On GitHub: https://github.com/glayzzle/php-parser
I had previously stumbled across the https://github.com/glayzzle/php-linter project but it is empty. I didn't see the other project.
This holds great promise. The only icing on the cake here would be if the parser could be told which PHP version to use, but we could get a list of language features that are added after PHP 5.2 and mark them as errors when the version of PHP on the server is not new enough. Amazing.
@westonruter it should be noted that php-parser in the demo uses an Abstract Syntax Tree to show the structure. It also has a token mode which returns an array compatible to token_get_all
. In fact the author of php-parser suggest it strictly follows token_get_all.
(I personally like the AST)
Moved to trac: https://core.trac.wordpress.org/ticket/41873
An initial linter could be one that uses the clike tokenizer in CodeMirror to ensure there are balanced braces.