|
1 | 1 | ## Table of contents
|
2 | 2 |
|
3 | 3 | * [A Project ruleset or a standard ?](#a-project-ruleset-or-a-standard-)
|
| 4 | +* [How does PHP_CodeSniffer determine which standard or ruleset to apply ?](#how-does-php_codesniffer-determine-which-standard-or-ruleset-to-apply-) |
4 | 5 | * [About standards](#about-standards)
|
5 | 6 | * [Creating an external standard for PHP_CodeSniffer](#creating-an-external-standard-for-php_codesniffer)
|
6 | 7 | * [Creating new rules](#creating-new-rules)
|
@@ -47,6 +48,21 @@ You may also find the [Customisable Sniff Properties](https://github.com/PHPCSSt
|
47 | 48 | <p align="right"><a href="#table-of-contents">back to top</a></p>
|
48 | 49 |
|
49 | 50 |
|
| 51 | +## How does PHP_CodeSniffer determine which standard or ruleset to apply ? |
| 52 | + |
| 53 | +1. The `--standard=...` CLI argument can be passed a comma-separated list of standards to apply, like `--standard=PSR12,myCustomRuleset.xml`. |
| 54 | + If the CLI argument is passed, those standard(s) are applied. |
| 55 | +2. If no `--standard=...` CLI argument is passed, PHP_CodeSniffer will look for the following files in the current directory and directories above it: `.phpcs.xml`, `phpcs.xml`, `.phpcs.xml.dist`, `phpcs.xml.dist`. |
| 56 | + If PHP_CodeSniffer finds one of these files, that will be the ruleset which will be applied. |
| 57 | + Note: the files PHPCS looks for are listed in order of precedence, so if both a `.phpcs.xml` file as well as a `phpcs.xml.dist` file are found, the `.phpcs.xml` file takes precedence. |
| 58 | +3. If no (project) ruleset file is found, PHP_CodeSniffer will check if a default standard has been set via `--config-set default_standard [Name]`. |
| 59 | + If so, PHP_CodeSniffer will use that standard. |
| 60 | + :warning: Setting the default standard is a user-specific setting, so should not be relied upon. |
| 61 | +4. If no system-default standard was set, PHP_CodeSniffer will apply the PEAR standard. |
| 62 | + |
| 63 | +<p align="right"><a href="#table-of-contents">back to top</a></p> |
| 64 | + |
| 65 | + |
50 | 66 | ## About standards
|
51 | 67 |
|
52 | 68 | In the context of PHP_CodeSniffer, a _"standard"_ is a predefined collection of rules for code to follow.
|
|
0 commit comments