WPTT / WPThemeReview

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

Analyse style.css before running the sniffs #174

Open jrfnl opened 6 years ago

jrfnl commented 6 years ago

Once the repo has been de-forked - see #169 -, a bootstrap file can be added which can analyse the style.css file in the theme root. This info can then be used by sniffs.

Another thing which we may or may not be able to do via the bootstrap file (needs investigation) is remove minified JS files from the list of files to analyse.

I know @grappler has done some initial work on something like this - @grappler is there a branch somewhere with what you did ?

Important: while having this information available can make certain sniffs possible/better, this isn't a silver bullet.

Example: Once this has been implemented, we can add a sniff checking add_theme_support() function calls to verify that all supported features are tagged in the style.css file, but we still will not be able to check that all tags used have the corresponding add_theme_support() function call as that won't be clear until the last token of the last file has been reached and at that point, we can no longer throw an error for it.

grappler commented 6 years ago

I think this is the code that I started https://gist.github.com/grappler/db2918097f54775680c0704890d9a394

dingo-d commented 5 years ago

I'll tag this as next release, so that we have 0.2.0 out before WCEU (and not to block Theme Sniffer new release) 🙂

jrfnl commented 5 years ago

Oh and just thinking: regarding the filtering out of minified JS/CSS files, instead of using the bootstrap for this, this can probably be done via a custom Filter class. (new feature in PHPCS 3)

Technical info:

Refs:

dingo-d commented 5 years ago

This is good to filter out the obvious minified files. But we'll still have issues with minified files that don't end in .min.js or .dev.js.

Definitely something we'd like for the next update :+1:

jrfnl commented 5 years ago

Well, the filter could also examine the contents of files, but to be fair, PHPCS itself already does this and is a lot better at detecting and excluding minified files since v3.