Skip to content

Feature suggestion: allow for "standards" to be hidden #18

Open
@jrfnl

Description

@jrfnl

Repost from squizlabs/PHP_CodeSniffer#2760:

Use-case: sniffs in generic sniff collections - like the Generic set in PHPCS - can be freely used by other standards, but shouldn't ever be included in a custom ruleset like <rule ref="Generic"/> as they may (and often will, like Generic) contain sniffs which contradict each other.

For the build-in Generic standard, PHPCS makes a hard-coded exception and doesn't list it when someone calls up phpcs -i.

https://github.com/squizlabs/PHP_CodeSniffer/blob/120c713213260a38988ac17816058ba3686f4e8f/src/Util/Standards.php#L107-L110

https://github.com/squizlabs/PHP_CodeSniffer/blob/120c713213260a38988ac17816058ba3686f4e8f/src/Util/Standards.php#L197-L200

I'd like to propose making that a feature available to external standards as well.
For one, I imagine the SlevomatCodingStandard could use it, but I see some more use-cases in the future.

I envision this can most easily be done by adding a new attribute to the ruleset element in the xsd and adjusting the code for the -i option to respect the setting found there.

Something like list with the default being true.

<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    name="Generic"
    list="false"
    xsi:noNamespaceSchemaLocation="../../../phpcs.xsd">

Implementation-wise, AFAICS this will be easiest to implement via the Standards::getInstalledStandardDetails() method and the Standards::getInstalledStandards() should then probably defer to that method instead of it being a stand-alone method.

Opinions ?


Thinking about this issue now, I have a feeling end-users might get confused if they don't see an expected standard when running phpcs -i, so hiding the standard(s) may not be the right action.

Possibly listing them as a separate category "Additional non-standard rulesets" or something like that ? (including Generic)
Or listing them with an * next to their name or something, might be better.

I'd love to see more input from end-users about what would be most helpful to them.


Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions