You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Advanced Usage: document the --generator CLI argument
PHPCS supports displaying the documentation that some sniffs ship with via the `--generator` CLI argument, but until now this feature was only mentioned briefly in the `phpcs --help` output rendered on the Usage page.
This commit adds a dedicated "Showing Sniff Documentation" section to the Advanced Usage page, covering what the feature does, the three available output formats, and how `--standard`, `--sniffs` and `--exclude` affect the rendered documentation.
Copy file name to clipboardExpand all lines: wiki/Advanced-Usage.md
+60Lines changed: 60 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -556,3 +556,63 @@ In PHP_CodeSniffer 3.x, the exit codes were:
556
556
And the following configuration flags were available: [`ignore_errors_on_exit`](https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki/Configuration-Options#ignoring-errors-when-generating-the-exit-code), [`ignore_warnings_on_exit`](https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki/Configuration-Options#ignoring-warnings-when-generating-the-exit-code).
557
557
558
558
<palign="right"><ahref="#table-of-contents">back to top</a></p>
559
+
560
+
561
+
## Showing Sniff Documentation
562
+
563
+
Some sniffs ship with documentation that explains what they check, along with valid and invalid code examples. PHP_CodeSniffer can print this documentation for the sniffs in a coding standard using the `--generator` command line argument.
564
+
565
+
```bash
566
+
$ phpcs --standard=PSR12 --generator=Text
567
+
```
568
+
569
+
For example, the documentation for the `PSR1.Files.SideEffects` sniff looks like this:
> Not every sniff in a coding standard ships with documentation. Sniffs without a documentation file are silently skipped, so the output may not cover every sniff that the standard would run during a scan.
577
+
578
+
### Available Documentation Formats
579
+
580
+
Three documentation formats are supported. The generator name is case-insensitive.
### Selecting Which Standards and Sniffs to Document
595
+
596
+
If `--standard` is omitted, PHP_CodeSniffer uses the default coding standard, the same way it does for a normal scan.
597
+
598
+
Multiple standards can be passed as a comma-separated list. The documentation for each standard is printed in the order the standards are listed:
599
+
600
+
```bash
601
+
$ phpcs --standard=PSR12,PSR1 --generator=Text
602
+
```
603
+
604
+
The `--sniffs` and `--exclude` command line arguments work the same way they do during a normal scan, allowing you to limit or exclude documentation for specific sniffs. See [Limiting Results to Specific Sniffs](https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki/Advanced-Usage#limiting-results-to-specific-sniffs) for the full syntax.
605
+
606
+
The following example only prints the documentation for a single sniff:
0 commit comments