Coding-standard: Choose only the rules I'm interested in

Created on 12 Nov 2019  路  8Comments  路  Source: slevomat/coding-standard

As a follow up of #763, which I wish you had been more helpful,

In README, the only way it suggests to select the rules we are interested at is by adding the WHOLE ruleset, and then exclude those we are NOT interested at.

So, instead of doing this:

<rule ref="vendor/slevomat/coding-standard/SlevomatCodingStandard/ruleset.xml">
    <exclude name="SlevomatCodingStandard....."/>
    <exclude name="SlevomatCodingStandard....."/>
    <exclude name="SlevomatCodingStandard....."/>
    <exclude name="SlevomatCodingStandard....."/>
    <exclude name="SlevomatCodingStandard....."/>
</rule>

For every single rule I'm not interested in,

Is it possible to explicitly put the rules I am actually interested in, and all others will be disabled by default?

Thank you very much.

Question

All 8 comments

@ghnp5 It's being done exactly like you say, e.g. https://github.com/mayflower/mo4-coding-standard/blob/master/MO4/ruleset.xml

@ghnp5 It's being done exactly like you say, e.g. https://github.com/mayflower/mo4-coding-standard/blob/master/MO4/ruleset.xml

The way that XML is, seems to be exactly the way I want it to be.
It's not as it says in README (and like I mentioned above), where you have to include the whole thing and then exclude.

But if I do it like on the link you provided to me, the rules will not apply, like if they are not recognized.

I want to be able to put explicit rules like this:

    <rule ref="SlevomatCodingStandard.Classes.ModernClassNameReference"/>
    <rule ref="SlevomatCodingStandard.Commenting.InlineDocCommentDeclaration"/>
    <rule ref="SlevomatCodingStandard.ControlStructures.AssignmentInCondition"/>

But without referencing the SlevomatCodingStandard's ruleset.xml, it doesn't seem to work.

Works on my machine... :man_shrugging:

Humm.. strange.

This is my phpcs.xml:

<?xml version="1.0" encoding="UTF-8"?>
<ruleset name="My Standard">
    <description>My Standard</description>
    <exclude-pattern>/vendor/*</exclude-pattern>
    <exclude-pattern>/node_modules/*</exclude-pattern>
    <exclude-pattern>/build/*</exclude-pattern>
    <rule ref="Generic.Classes.DuplicateClassName"/>
    <rule ref="Generic.CodeAnalysis.EmptyStatement"/>
    <rule ref="Generic.CodeAnalysis.ForLoopWithTestFunctionCall"/>
    ...
    <rule ref="SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing"/>
</ruleset>

Then I closed VS Code and re-opened, opened a PHP file in the workspace that does not have declare strict, made a modification and saved, and the error doesn't trigger.

But if I do:

<?xml version="1.0" encoding="UTF-8"?>
<ruleset name="My Standard">
    <description>My Standard</description>
    <exclude-pattern>/vendor/*</exclude-pattern>
    <exclude-pattern>/node_modules/*</exclude-pattern>
    <exclude-pattern>/build/*</exclude-pattern>
    <rule ref="Generic.Classes.DuplicateClassName"/>
    <rule ref="Generic.CodeAnalysis.EmptyStatement"/>
    <rule ref="Generic.CodeAnalysis.ForLoopWithTestFunctionCall"/>
    ...
    <rule ref="vendor/slevomat/coding-standard/SlevomatCodingStandard/ruleset.xml"/>
</ruleset>

It triggers the error for define strict missing.

Ok, solution is to do this:

<config name="installed_paths" value="../../slevomat/coding-standard"/>
<rule ref="SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing"/>

Thanks!

@ghnp5

In README, the only way it suggests to select the rules we are interested at is by adding the WHOLE ruleset

You did not read the README carefully.

You did not read the README carefully.

And you were not helpful at all.

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings