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

Analyse style.css before running the sniffs #174

Open
jrfnl opened this issue Aug 19, 2018 · 5 comments
Open

Analyse style.css before running the sniffs #174

jrfnl opened this issue Aug 19, 2018 · 5 comments

Comments

@jrfnl
Copy link

jrfnl commented Aug 19, 2018

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
Copy link
Member

grappler commented Sep 2, 2018

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

@dingo-d
Copy link
Member

dingo-d commented May 18, 2019

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
Copy link
Author

jrfnl commented May 19, 2019

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:

  • Add the filter in a new top-level folder.
  • Hook it into the ruleset to be used by default via a <arg> directive.
  • As for the filter itself:
    • It should probably look through the complete list of filenames for JS files initially to determine whether the .dev.js vs .js or the .js vs .min.js file name pattern is used.
    • If its clear one or the other is used, then:
      • for the first: any .js files where a .dev.js file is also found with the same name can be removed from the filelist.
      • for the second: any .min.js files where a .js file is also found with the same name can be removed from the filelist.
    • If both are used - min and dev - we need to do some more complicated logic.

Refs:

@dingo-d
Copy link
Member

dingo-d commented May 20, 2019

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 👍

@jrfnl
Copy link
Author

jrfnl commented May 20, 2019

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.

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

3 participants