Skip to content

How to add single file without extension to check? #2916

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

Closed
kubawerlos opened this issue Mar 27, 2020 · 6 comments
Closed

How to add single file without extension to check? #2916

kubawerlos opened this issue Mar 27, 2020 · 6 comments
Milestone

Comments

@kubawerlos
Copy link

I want to add a single file without extension (or with a name starting with a dot), but cannot achieve this. Neither with <file> in XML or with the command line.

E.g. when I run ./bin/phpcs ./bin/phpcs ./src/Config.php in this repo the output is 1 / 1 (100%), where the 1 is for the latter file.

I've found this: https://github.com/squizlabs/PHP_CodeSniffer/blob/3.5.4/src/Filters/Filter.php#L168 and this implies that this line: https://github.com/squizlabs/PHP_CodeSniffer/blob/3.5.4/phpcs.xml.dist#L6 is useless, right?

@gsherwood
Copy link
Member

Sorry, I missed the notification for this issue.

You are correct, files without an extension are filtered out and the bin directory of PHPCS is not actually checked during a test run.

There is no way to tell PHPCS to check files without an extension. Having PHPCS pick up files with no extension by default would break quite a lot of test runs, so that's not something I want to do. I think that specifying the file path directly would be fine though.

I'm going to throw this on the 4.0 roadmap because I've removed JS and CSS tokenizing support there, which lets PHPCS assume that all specified files are PHP files - as it originally did. This makes re-introducing support for files with no extension much easier.

@gsherwood gsherwood added this to the 4.0.0 milestone May 4, 2020
@gsherwood
Copy link
Member

I've changed the behaviour of PHPCS in the 4.0 branch so that files with no extension are checked if you pass in the path directly on the command line, or via a ruleset <file> tag. I've also updated the PHPCS ruleset to specify the 2 files in the bin dir so they are checked now.

@kubawerlos
Copy link
Author

Thanks @gsherwood

@AlexSkrypnyk
Copy link

AlexSkrypnyk commented Sep 8, 2023

@gsherwood
is there a chance this can be backported to v3? It has been 3 years since this was raised and v4 is still not out. This functionality is important to scan single-file php scripts.

@AlexSkrypnyk
Copy link

@jrfnl @gsherwood
I'm happy to sponsor this backporting work to get it prioritised for v3.

@jrfnl
Copy link
Contributor

jrfnl commented Apr 14, 2025

@jrfnl @gsherwood I'm happy to sponsor this backporting work to get it prioritised for v3.

@AlexSkrypnyk It won't be backported to 3.x, but 4.0 is around the corner by now - see PHPCSStandards/PHP_CodeSniffer#924
Oh and supporting the project with funding is always appreciated and welcome: https://github.com/sponsors/PHPCSStandards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants