PHPCSStandards / PHPCSUtils

A suite of utility functions for use with PHP_CodeSniffer
https://phpcsutils.com/
GNU Lesser General Public License v3.0
54 stars 7 forks source link

PHPCSUtils causes `ERROR: No sniffs were registered` #435

Closed thelovekesh closed 1 year ago

thelovekesh commented 1 year ago

As of https://github.com/squizlabs/PHP_CodeSniffer/commit/7df3c330929644bc494d2b2e8485ba300756fa87 PHPCS throws an expectation No sniffs were registered if there are no sniffs registered.

Since PHPCSUtils is included as standard without sniffs, it throws an exception on exec phpcs --standard=PHPCSUtils -es.

A possible solution might be to include an empty sniff to avoid this.

DummySniff ```php

ping @jrfnl @gsherwood

jrfnl commented 1 year ago

@thelovekesh Why are you running phpcs --standard=PHPCSUtils ? I mean, I'd like to understand your use-case here as in my mind, there is none.

PHPCSUtils is not a standard to be run by end-users. It is a set of helper functions for external PHPCS standards.

If this is caused by PHPCSUtils being listed as a "standard" via phpcs -i, there is already an issue open about that in the PHPCS repo: https://github.com/squizlabs/PHP_CodeSniffer/issues/2760

jrfnl commented 1 year ago

A possible solution might be to include an empty sniff to avoid this.

Note: I will not include an empty sniff.

The error/exception thrown by PHPCS is there for a reason and is pointing out something helpful, i.e. the scan being done is useless as-is as no sniffs are registered. This should be solved by whomever is running the scan, not in PHPCSUtils.

thelovekesh commented 1 year ago

Why are you running phpcs --standard=PHPCSUtils ? I mean, I'd like to understand your use-case here as in my mind, there is none.

@jrfnl You can find one here. According to this, all sniffs are get listed and then revalidated if there are any duplicate or obsolete sniffs.

I will try to handle it on upstream but removing the PHPCSUtils from phpcs -i per https://github.com/squizlabs/PHP_CodeSniffer/issues/2760 doesn't seems a great solution either as the user will not be able to learn if PHPCSUtils is loaded.

jrfnl commented 1 year ago

Why are you running phpcs --standard=PHPCSUtils ? I mean, I'd like to understand your use-case here as in my mind, there is none.

@jrfnl You can find one here. According to this, all sniffs are get listed and then revalidated if there are any duplicate or obsolete sniffs.

Que ? I still don't understand why that is done or even why that would ever be useful ? - I mean, rulesets will often include the same sniff twice, once from within a standard and once to add custom properties, so it just doesn't sound right to begin with, but then I may not understand correctly what that custom program really does (and I am resisting the temptation to look into it more deeply as I'm officially on holiday).

I will try to handle it on upstream

And that's how it should be. If you need help getting that sorted, let me know and I can possibly help you with that once I'm back from my break.

but removing the PHPCSUtils from phpcs -i per squizlabs/PHP_CodeSniffer#2760 doesn't seems a great solution either as the user will not be able to learn if PHPCSUtils is loaded.

Agreed, see my latest comment in that thread.

thelovekesh commented 1 year ago

Thanks for catching up. Will add you to the upstream conversation once I start one.

I'm officially on holiday

I know from Twitter 😄 ; Enjoy the break 🎉 !

thelovekesh commented 1 year ago

Sorry for the trouble. I found a flag to ignore standards without sniffs on the tools which I am using.

I am closing this and will continue the discussion on https://github.com/squizlabs/PHP_CodeSniffer/issues/2760

jrfnl commented 1 year ago

@thelovekesh Glad to hear you found a good solution.