WPTT / theme-sniffer

Theme Sniffer plugin using sniffs.
MIT License
270 stars 3 forks source link

ignored files passed are not respected in custom file sorting #112

Closed timelsass closed 5 years ago

timelsass commented 5 years ago

In the custom file sorting here: https://github.com/WPTRT/theme-sniffer/blob/feature/use-namespace/src/callback/class-run-sniffer-callback.php#L389

all files are passed in and looped. This runs the file_get_contents calls on directories that are quite large, which are typically ignored - ie my node_modules folder. This is causing php timeout and error in console.

dingo-d commented 5 years ago

Yeah, in the $all_files = $theme->get_files( [ 'php' ], -1, false ); I should exclude node_modules and vendor folders by default.

I haven't thought of that because the built themes shouldn't contain them - well vendors could be contained due to autoloader, but should still be excluded from the checks. Good catch 👍

dingo-d commented 5 years ago

I have pushed the changes in the branch, can you test if it's ok?

EDIT: Tested it on the boileplate from my company and it excludes the node_modules and vendor folders.

Thanks for the find!

timelsass commented 5 years ago

Yes that appears to work, I think in the future it should be considered creating the file using https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Files/FileList.php and passing the file extensions in the configs so it behaves the same way as how the cli operates like phpcs --extensions. Then in the filelist it can be filtered out with the further critera and logic. This would also make it so the ignore parameters will come through (currently they are hardcoded in class-run-sniffer-callback.php ).

dingo-d commented 5 years ago

You mean define our own instance of FileList class with custom arguments and ruleset? Tbh don't know how that works in tandem with the custom runner 🤷‍♂️ I'm all open for suggestions 🙂

This would also make it so the ignore parameters will come through (currently they are hardcoded in class-run-sniffer-callback.php ).

Come through where exactly? The custom rulesets? 🤔 Because I don't think that the rulesets are ignoring files and folders (to my knowledge only custom rulesets are, WPThemeReview and WPCS are not ignoring folders)