Skip to content

Commit 7f97c87

Browse files
committed
About Standards: add section about how PHPCS determines the standard to use
1 parent bc64ea7 commit 7f97c87

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

wiki/About-Standards-for-PHP_CodeSniffer.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## Table of contents
22

33
* [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-)
45
* [About standards](#about-standards)
56
* [Creating an external standard for PHP_CodeSniffer](#creating-an-external-standard-for-php_codesniffer)
67
* [Creating new rules](#creating-new-rules)
@@ -47,6 +48,21 @@ You may also find the [Customisable Sniff Properties](https://github.com/PHPCSSt
4748
<p align="right"><a href="#table-of-contents">back to top</a></p>
4849

4950

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+
5066
## About standards
5167

5268
In the context of PHP_CodeSniffer, a _"standard"_ is a predefined collection of rules for code to follow.

0 commit comments

Comments
 (0)