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.67k stars 1.48k forks source link

Use codesniffer without Generic and Squiz #3725

Closed duskohu closed 1 year ago

duskohu commented 1 year ago

Describe the bug How can validate code only PSR2 standard, without Generic and Squiz? I have config file, only for use tabs and remove Too Long Line Length. Now I have in report Squiz and Generic

Code sample

phpcs --standard=.phpcs.xml

Custom ruleset

<?xml version="1.0"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="test">
    <file>./../../web</file>

    <arg name="standard" value="PSR2"/>
    <arg name="extensions" value="php"/>
    <arg name="basepath" value="./../../"/>
    <arg name="tab-width" value="4"/>

    <rule ref="PSR2">
        <exclude name="Generic.WhiteSpace.DisallowTabIndent"/>
        <exclude name="Generic.Files.LineLength.TooLong"/>
    </rule>

    <rule ref="Generic.WhiteSpace.DisallowSpaceIndent"/>

    <rule ref="Generic.WhiteSpace.ScopeIndent">
        <properties>
            <property name="indent" value="4"/>
            <property name="tabIndent" value="true"/>
        </properties>
    </rule>
</ruleset>

Versions (please complete the following information): PHP_CodeSniffer version 3.7.1 (stable)

jrfnl commented 1 year ago

The PSR2 ruleset only applies the rules as they are defined in PSR2 and makes use of a variety of sniffs to do so. So the PSR2 standard uses sniffs from the Generic and Squiz standards, it doesn't use those standards as such, so you are validating only against PSR2.

duskohu commented 1 year ago

@jrfnlthx, and how?

jrfnl commented 1 year ago

@duskohu Sorry, but I don't know what you are asking. If you want to check your code against PSR2, you will get sniffs from Generic and Squiz as otherwise, you are only checking code against a subset of rules from PSR2.