WordPress / better-code-editing

[✅ Merged into 4.9-alpha] Better Code Editing WordPress plugin
https://wordpress.org/plugins/better-code-editing/
37 stars 16 forks source link

Add PHP linter #48

Closed westonruter closed 6 years ago

westonruter commented 6 years ago

An initial linter could be one that uses the clike tokenizer in CodeMirror to ensure there are balanced braces.

westonruter commented 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.

westonruter commented 6 years ago

We could possibly implement a lightweight linter in PHP that uses CodeMirror's tokenizer to do brace matching.

westonruter commented 6 years ago

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.

rheinardkorf commented 6 years ago

@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)

westonruter commented 6 years ago

Moved to trac: https://core.trac.wordpress.org/ticket/41873