1

I'm setting up PHP CodeSniffer as a linter for my code and I have an error which I want to ignore.

In order to do that, I should be able to put the line // phpcs:ignore Name.Of.The.Rule before the line that is an exception to that rule.

Unfortunately, I don't know how I can find which of the rules I have to ignore. Is there a way to display the rule producing the error?

For now, I searched the error message in my vendor folder, resulting in 4 different entries. I'm not sure I know which is the one called.

The error summary looks like that:

----------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
 14 | ERROR | Method name "ActivityRules::is_after" is not in camel
    |       | caps format
----------------------------------------------------------------------

I would love to have something like that:

---------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
---------------------------------------------------------------------------------------------------
 14 | ERROR | Method name "ActivityRules::is_after" is not in camel   | SomeStandard.Category         
    |       | caps format                                             | .NameOfTheSniff.RuleCalled
---------------------------------------------------------------------------------------------------

EDIT:

I don't need you to tell me it's PSR1.Methods.CamelCapsMethodName.NotCamelCaps, I know how to find the rule by hand the hard way, by trial and error. I'd like to know if there is an easy way to do it.

SteeveDroz
  • 6,006
  • 6
  • 33
  • 65

1 Answers1

2

Use phpcs -s

The output of phpcs --help includes the available options:

phpcs --help
...
 -s    Show sniff codes in all reports
...

The 'Show sniff codes in all reports' option results in this output format:

➜  /tmp phpcs -s example.php

FILE: /private/tmp/example.php
----------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
 14 | ERROR | [ ] Method name "ActivityRules::is_after" is not in camel caps format
    |       |     (PEAR.NamingConventions.ValidFunctionName.NotCamelCaps)
----------------------------------------------------------------------
Time: 30ms; Memory: 6MB

➜  /tmp

Which is hopefully close enough to what you're looking for here.

AD7six
  • 63,116
  • 12
  • 91
  • 123