10

We're using PSR0, PSR1 and PSR2 standards in our project, but I want to exclude a specific file from just the PSR0 namespace checking rule. Is there a way I can add a comment to the file, so phpcs ignores this rule:

Each class must be in a namespace of at least one level...

Lajos Veres
  • 13,595
  • 7
  • 43
  • 56
josef.van.niekerk
  • 11,941
  • 20
  • 97
  • 157

1 Answers1

18

Here: http://pear.php.net/manual/en/package.php.php-codesniffer.annotated-ruleset.php

They show this example:

<!--
    You can also hard-code ignore patterns for specific sniffs,
    a feature not available on the command line.

    The code here will hide all messages from the Squiz DoubleQuoteUsage
    sniff for files that match either of the two exclude patterns.
 -->
 <rule ref="Squiz.Strings.DoubleQuoteUsage">
    <exclude-pattern>*/tests/*</exclude-pattern>
    <exclude-pattern>*/data/*</exclude-pattern>
 </rule>
Lajos Veres
  • 13,595
  • 7
  • 43
  • 56
  • This is what I ended up doing, plus writing my own ruleset from scratch. – josef.van.niekerk Dec 24 '13 at 06:45
  • 1
    see also [extending wordpress ruleset](https://stackoverflow.com/questions/53635328/how-to-setup-php-codesniffer-that-extend-wordpress-coding-standards-autofix-er/53653193#53653193) – Top-Master Apr 01 '19 at 12:04