Custom coding standards sniffs not working - PHP_CodeSniffer_Exception

Viewed 2881

I am working on creating a custom ruleset for sniffing code in WordPress, and I'm using PHP_CodeSniffer for that.

The custom ruleset can be found here: https://github.com/infinum/coding-standards-wp.

Now when I try to use them I get this error

Fatal error: Uncaught exception 'PHP_CodeSniffer_Exception' with message 'Referenced sniff "WordPress" does not exist' in /wpcs/vendor/squizlabs/php_codesniffer/CodeSniffer.php:1167
Stack trace:
#0 /wpcs/vendor/squizlabs/php_codesniffer/CodeSniffer.php(780): PHP_CodeSniffer->_expandRulesetReference(Object(SimpleXMLElement), '/...', 0)
#1 /wpcs/vendor/squizlabs/php_codesniffer/CodeSniffer.php(578): PHP_CodeSniffer->processRuleset('/...')
#2 /wpcs/vendor/squizlabs/php_codesniffer/CodeSniffer/CLI.php(956): PHP_CodeSniffer->initStandard(Array, Array, Array)
#3 /wpcs/vendor/squizlabs/php_codesniffer/CodeSniffer/CLI.php(113): PHP_CodeSniffer_CLI->process()
#4 /wpcs/vendor/squizlabs/php_codesniffer/scripts/phpcs(25): PHP_CodeSniffer_CLI->runphpcs()
#5 {main}
  thrown in /wpcs/vendor/squizlabs/php_codesniffer/CodeSniffer.php on line 1167

I have no idea how to fix this. I have searched all around and modeled the ruleset like other people have, and I have no idea why this happens.

EDIT:

So when I install the standards using composer in my project and run

vendor/bin/phpcs --standard=vendor/infinum/coding-standards-wp wp-content/themes/twentyseventeen/functions.php

It works, it's just that it's not picking up my custom sniffs for some reason.

And when I put the coding standard in my globally installed wpcs folder, I get the above error in my Sublime console.

EDIT 2:

Ok, so I have wpcs installed in my home folder. In there I placed Infinum folder and inside there are my sniffs. This works only if I remove

 <config name="installed_paths" value="vendor/wp-coding-standards/wpcs"/>

from ruleset.xml

My Sublime will pick it up and the sniffs (now without namespaces) work as they should, all great.

When I install it in a project using composer, I get the above error again.

The difference when it's loaded globally (so that it's available to Sublime) the folder structure looks like this

wpcs
  -- Infinum
    -- Sniffs
      -- Classes
        OnlyClassInFileSniff.php
      -- Shortcodes
        DisallowDoShortcodeSniff.php
    composer.json
    README.md
    ruleset.xml

And when I install it with composer in my project it is located inside vendor folder

vendor
  -- bin
  -- composer
  -- infinum
    -- coding-standards-wp
      -- Sniffs
        -- Classes
          OnlyClassInFileSniff.php
        -- Shortcodes
          DisallowDoShortcodeSniff.php
        composer.json
        README.md
        ruleset.xml
  -- squizlabs
  -- wp-coding-standards
    autoload.php

FINAL EDIT

Ok, so I made it work locally.

It picks up the custom sniffs and all.

But now if I place it in my global wpcs folder I cannot get it to work. Well I guess I'll just redo this globally so that it works with Sublime...

1 Answers
Related