wdes/coding-standard

The Wdes coding standard

Installs: 1 708

Dependents: 5

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

Type:phpcodesniffer-standard

v3.0.0 2021-03-21 14:26 UTC

This package is auto-updated.

Last update: 2021-04-12 15:21:18 UTC


README

The Wdes coding-standard

Rules to disable for PHP 5 compat

  • Generic.Arrays.DisallowLongArraySyntax

How to add it

  • Run composer require --dev wdes/coding-standard
  • Create file: phpcs.xml with the contents below
<?xml version="1.0"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd">

    <!-- Show progress and sniff codes -->
    <arg value="ps"/>
    <arg name="colors"/>
    <!-- Make sniff report relative -->
    <arg name="basepath" value="."/>

    <file>.</file>
    <exclude-pattern>*/tmp/*</exclude-pattern>
    <exclude-pattern>*/vendor/*</exclude-pattern>
    <exclude-pattern>*/build/*</exclude-pattern>
    <exclude-pattern>*/node_modules/*</exclude-pattern>

    <rule ref="Wdes"></rule>
</ruleset>
  • Remove phpcs from your dev deps if you have it, we require it for you. Use composer remove squizlabs/php_codesniffer --dev

  • Run ./vendor/bin/phpcs to see the coding standard errors

  • Run ./vendor/bin/phpcbf to try to fix them

How to exclude rules

Examples of ways to exclude rules

<?xml version="1.0"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd">

    <!-- Show progress and sniff codes -->
    <arg value="ps"/>
    <!-- Cache file -->
    <arg name="cache" value=".php_cs.cache"/>
    <arg name="colors"/>

    <!-- Paths to check -->
    <file>src</file>
    <file>scripts</file>
    <file>examples</file>
    <file>tests</file>

    <!-- Exclude files from phpcs -->
    <exclude-pattern>*/src/Resources/themes/*</exclude-pattern>
    <exclude-pattern>*/tests/phar/data/**/*</exclude-pattern>

    <!-- Exclude a rule from the Wdes standard -->
    <rule ref="Wdes">
        <exclude name="Generic.Formatting.MultipleStatementAlignment.NotSameWarning"/>
    </rule>

    <!-- Or lower the severity to zero -->
    <rule ref="Generic.Files.LineLength.TooLong">
        <severity>0</severity>
    </rule>

    <!-- Or exclude the rule -->
    <exclude name="PSR1.Files.SideEffects.FoundWithSymbols"/>

    <!-- Or remove the rule for all files -->
    <rule ref="Generic.PHP.NoSilencedErrors.Discouraged">
        <exclude-pattern>*</exclude-pattern>
    </rule>

</ruleset>