2

I have a ruleset with some custom sniffs. I have the ruleset in my project directory/repository, but I can't work out how to keep the custom sniffs there.

If I put a relative link into the ruleset:

 <rule ref="./MySniffs/foo"/> 

then it throws this error:

PHP_CodeSniffer_Exception: Referenced sniff "./MySniffs/foo" 
does not exist in C:\path\to\php\php\pear\PHP\CodeSniffer.php

So the relative path is worked out from the CodeSniffer.php file and not from the ruleset.

Is it possible to make the ruleset point to the custom sniff without using absolute paths?

I need to use relative paths because this is a repository with multiple instances.

SystemicPlural
  • 5,629
  • 9
  • 49
  • 74

1 Answers1

3

Sorted it.

It does work. My problem was that the sniff class name was not named correctly.

The folder that contains the ruleset has to be part of the sniff class name. The following paths are required.

/path/to/project/MyRuleset/ruleset.xml
/path/to/project/MyRuleset/Sniffs/SniffGroup/SniffNameSniff.php

And this would make the following rule work.

 <rule ref="MyRuleset.SniffGroup.SniffName"/> 

And this would be the sniff class name:

class MyRuleset_Sniffs_SniffGroup_SniffNameSniff implements PHP_CodeSniffer_Sniff
SystemicPlural
  • 5,629
  • 9
  • 49
  • 74