squizlabs / PHP_CodeSniffer

PHP_CodeSniffer tokenizes PHP files and detects violations of a defined set of coding standards.
BSD 3-Clause "New" or "Revised" License
10.66k stars 1.48k forks source link

PHP_CodeSniffer does not test PHP files with no extensions #1754

Closed Loupax closed 5 years ago

Loupax commented 6 years ago

Version 3.1.1 (stable)

According to the documentation, I should be able to check these files by passing a specific file as an argument but it doesn't seem to be the case. After some digging in the source code I found that the reason the files aren't getting checked is this line.

Is there a way to bypass this filtering? Will you accept a MR that checks the shebang of files without extensions before filtering them out?

gsherwood commented 6 years ago

According to the documentation, I should be able to check these files by passing a specific file as an argument but it doesn't seem to be the case.

Thanks for reporting this. This is the 2.x behaviour but 3.x was changed to do proper checking on all supplied paths. I'll remove that from the docs.

Is there a way to bypass this filtering? Will you accept a MR that checks the shebang of files without extensions before filtering them out?

The only way to do that would be to create your own filter class and override the method that performs that check.

I'm not really keen on changing PHPCS to open files with no extension to see if they look like PHP files or not. I have a couple of those files but I don't think they are common enough to change PHPCS in that way. I'd rather have a way of specifying particular file paths to be checked for those specific cases. But needs more thought I think.

Loupax commented 6 years ago

Just to be sure, the only way of extending PHPCS is to create my own fork, or there is some functionality that allows me to create my own filters and somehow plug them?

gsherwood commented 6 years ago

You can create a filter class and specify it using the --filter=/path/to/filter command line argument. I'd copy this one and modify it if you want to give it a go: https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Filters/ExactMatch.php

You can do the same thing with report classes if that's something you're interested in.

Loupax commented 6 years ago

Thank you very much, this will work greatly!

gsherwood commented 5 years ago

Closing as I don't think the default behaviour should now be changed