Skip to content

Commit 10afb97

Browse files
jrfnljoachim-n
andcommitted
Update sniff code vs error code + additional info about this in Reporting and Advanced Usage
Refs: #319, #328 Co-authored-by: Joachim Noreiko <joachim@107701.no-reply.drupal.org>
1 parent 1c48a8b commit 10afb97

File tree

4 files changed

+49
-12
lines changed

4 files changed

+49
-12
lines changed

wiki/Advanced-Usage.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,15 @@ bar($foo,false);
165165
## Limiting Results to Specific Sniffs
166166
By default, PHP_CodeSniffer will check your code using all sniffs in the specified standard. Sometimes you may want to find all occurrences of a single error to eliminate it more quickly, or to exclude sniffs to see if they are causing conflicts in your standard. PHP_CodeSniffer allows you to specify a list of sniffs to limit results to using the `--sniffs` command line argument, or a list of sniffs to exclude using the `--exclude` command line argument. Sniff codes are separated by commas.
167167

168+
> [!NOTE]
169+
> To find out the sniff code of an error message, use the `-s` command line argument.
170+
>
171+
> The source codes shown when using the `-s` flag are build up like this:
172+
> `StandardName.Category.SniffName.ErrorCode`
173+
>
174+
> This four-part name is the identifier of a particular error or warning, commonly referred to as the _error code_.
175+
> The first three parts of the name `StandardName.Category.SniffName` is the _sniff code_.
176+
168177
> [!NOTE]
169178
> All sniffs specified on the command line must be used in the coding standard you are using to check your files.
170179

wiki/Home.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
PHP_CodeSniffer is a set of two PHP scripts; the main phpcs script that tokenizes PHP, JavaScript and CSS files to detect violations of a defined coding standard, and a second phpcbf script to automatically correct coding standard violations. PHP_CodeSniffer is an essential development tool that ensures your code remains clean and consistent.
22

3-
A coding standard in PHP_CodeSniffer is a collection of sniff files. Each sniff file checks one part of the coding standard only. Multiple coding standards can be used within PHP_CodeSniffer so that the one installation can be used across multiple projects. The default coding standard used by PHP_CodeSniffer is the PEAR coding standard.
3+
A coding standard in PHP_CodeSniffer is a collection of sniff files. Each sniff file checks one part of the coding standard only. Each sniff can yield multiple error codes, a different one for each aspect of the code which was checked and found non-compliant
4+
5+
Multiple coding standards can be used within PHP_CodeSniffer so that the one installation can be used across multiple projects. The default coding standard used by PHP_CodeSniffer is the PEAR coding standard.
46

57
## Example
68
To check a file against the PEAR coding standard, simply specify the file's location.

wiki/Reporting.md

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,30 +24,29 @@
2424
***
2525

2626
## Printing Full and Summary Reports
27-
Both the full and summary reports can additionally show information about the source of errors and warnings. Source codes can be used with the `--sniffs` command line argument to only show messages from a specified list of sources. To include source codes in the report, use the `-s` command line argument.
27+
When running a scan, by default, the full report is displayed.
28+
29+
$ phpcs /path/to/code/myfile.php
2830

29-
$ phpcs -s /path/to/code/myfile.php
30-
3131
FILE: /path/to/code/classA.php
3232
--------------------------------------------------------------------------------
3333
FOUND 4 ERRORS AND 1 WARNING AFFECTING 5 LINES
3434
--------------------------------------------------------------------------------
3535
2 | ERROR | [ ] Missing file doc comment
36-
| | (PEAR.Commenting.FileComment.Missing)
3736
4 | ERROR | [x] TRUE, FALSE and NULL must be lowercase; expected "false" but
38-
| | found "FALSE" (Generic.PHP.LowerCaseConstant.Found)
37+
| | found "FALSE"
3938
6 | ERROR | [x] Line indented incorrectly; expected at least 4 spaces, found
40-
| | 1 (PEAR.WhiteSpace.ScopeIndent.Incorrect)
39+
| | 1
4140
9 | ERROR | [ ] Missing function doc comment
42-
| | (PEAR.Commenting.FunctionComment.Missing)
4341
11 | WARNING | [x] Inline control structures are discouraged
44-
| | (Generic.ControlStructures.InlineControlStructure.Discouraged)
4542
--------------------------------------------------------------------------------
4643
PHPCBF CAN FIX THE 3 MARKED SNIFF VIOLATIONS AUTOMATICALLY
4744
--------------------------------------------------------------------------------
4845

49-
$ phpcs -s --report=summary /path/to/code
50-
46+
To see a summary of the errors and warnings per file, use the `--report=summary` option.
47+
48+
$ phpcs --report=summary /path/to/code
49+
5150
PHP CODE SNIFFER REPORT SUMMARY
5251
--------------------------------------------------------------------------------
5352
FILE ERRORS WARNINGS
@@ -59,6 +58,33 @@ Both the full and summary reports can additionally show information about the so
5958
A TOTAL OF 6 ERROR(S) AND 3 WARNING(S) WERE FOUND IN 3 FILE(S)
6059
--------------------------------------------------------------------------------
6160

61+
The full report can also show information about the source of errors and warnings. To include source codes in the report,
62+
use the `-s` command line argument.
63+
64+
$ phpcs -s /path/to/code/myfile.php
65+
66+
FILE: /path/to/code/classA.php
67+
--------------------------------------------------------------------------------
68+
FOUND 4 ERRORS AND 1 WARNING AFFECTING 5 LINES
69+
--------------------------------------------------------------------------------
70+
2 | ERROR | [ ] Missing file doc comment
71+
| | (PEAR.Commenting.FileComment.Missing)
72+
4 | ERROR | [x] TRUE, FALSE and NULL must be lowercase; expected "false" but
73+
| | found "FALSE" (Generic.PHP.LowerCaseConstant.Found)
74+
6 | ERROR | [x] Line indented incorrectly; expected at least 4 spaces, found
75+
| | 1 (PEAR.WhiteSpace.ScopeIndent.Incorrect)
76+
9 | ERROR | [ ] Missing function doc comment
77+
| | (PEAR.Commenting.FunctionComment.Missing)
78+
11 | WARNING | [x] Inline control structures are discouraged
79+
| | (Generic.ControlStructures.InlineControlStructure.Discouraged)
80+
--------------------------------------------------------------------------------
81+
PHPCBF CAN FIX THE 3 MARKED SNIFF VIOLATIONS AUTOMATICALLY
82+
--------------------------------------------------------------------------------
83+
84+
Source codes can be used with the `--sniffs` command line argument to only show messages from a specified list of sources
85+
and with the `--exclude` command line argument to silence the messages from a specified list of sources.
86+
[Learn how](https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki/Advanced-Usage#limiting-results-to-specific-sniffs).
87+
6288
<p align="right"><a href="#table-of-contents">back to top</a></p>
6389

6490

wiki/Usage.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Usage: phpcs [-nwlsaepqvi] [-d key[=value]] [--colors] [--no-colors]
2929
-n Do not print warnings (shortcut for --warning-severity=0)
3030
-w Print both warnings and errors (this is the default)
3131
-l Local directory only, no recursion
32-
-s Show sniff codes in all reports
32+
-s Show error codes in all reports
3333
-a Run interactively
3434
-e Explain a standard by showing the sniffs it includes
3535
-p Show progress of the run

0 commit comments

Comments
 (0)