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
Copy file name to clipboardExpand all lines: wiki/Advanced-Usage.md
+18-12Lines changed: 18 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -25,12 +25,12 @@
25
25
26
26
By default, PHP_CodeSniffer will check any file it finds with a `.inc`, `.php`, `.js` or `.css` extension, although not all standards will actually check all these file types. Sometimes, this means that PHP_CodeSniffer is not checking enough of your files. Sometimes, the opposite is true. PHP_CodeSniffer allows you to specify a list of valid file extensions using the `--extensions` command line argument. Extensions are separated by commas.
Sometimes you want PHP_CodeSniffer to run over a very large number of files, but you want some files and folders to be skipped. The `--ignore` command line argument can be used to tell PHP_CodeSniffer to skip files and folders that match one or more patterns.
44
44
45
-
In the following example, PHP_CodeSniffer will skip all files inside the package's tests and data directories. This is useful if you are checking a package but don't want your test or data files to conform to your coding standard.
45
+
In the following example, PHP_CodeSniffer will skip all files inside the package's `tests` and `data` directories. This is useful if you are checking a package but don't want your test or data files to conform to your coding standard.
46
46
```bash
47
47
$ phpcs --ignore=*/tests/*,*/data/* /path/to/code
48
48
```
49
49
50
50
> [!IMPORTANT]
51
-
> The ignore patterns are treated as regular expressions. If you do specify a regular expression, be aware that `*` is converted to `.*` for the convenience in simple patterns, like those used in the example above. So use `*` anywhere you would normally use `.*`. Also ensure you escape any `.` characters that you want treated as a literal dot, such as when checking file extensions. So if you are checking for `.inc` in your ignore pattern, use `\.inc` instead.
51
+
> The ignore patterns are treated as regular expressions. If you do specify a regular expression, be aware that `*` is converted to `.*` for convenience in simple patterns, like those used in the example above. So use `*` anywhere you would normally use `.*`. Also ensure you escape any `.` characters that you want treated as a literal dot, such as when checking file extensions. So if you are checking for `.inc` in your ignore pattern, use `\.inc` instead.
52
52
53
-
You can also tell PHP_CodeSniffer to ignore a file using a special comment inserted at the top of the file. This will stop the file being checked even if it does not match the ignore pattern.
53
+
You can also tell PHP_CodeSniffer to ignore a file using a special comment inserted at the top of the file. This will stop the file from being checked, even if it does not match the ignore pattern.
54
54
55
55
```php
56
56
<?php
@@ -61,9 +61,10 @@ $xmlPackage->send();
61
61
```
62
62
63
63
> [!NOTE]
64
-
> Before PHP_CodeSniffer version 3.2.0, use `// @codingStandardsIgnoreFile` instead of `// phpcs:ignoreFile`. The `@codingStandards` syntax is deprecated and will be removed in PHP_CodeSniffer version 4.0.
64
+
> Before PHP_CodeSniffer version 3.2.0, use `// @codingStandardsIgnoreFile` instead of `// phpcs:ignoreFile`.
65
+
> The `@codingStandards` syntax is deprecated and will be removed in PHP_CodeSniffer version 4.0.
65
66
66
-
> [!NOTE]
67
+
> [!TIP]
67
68
> The `phpcs:ignoreFile` comment syntax does not allow for a specific set of sniffs to be ignored for a file. Use the `phpcs:disable` comment syntax if you want to disable a specific set of sniffs for the entire file.
68
69
69
70
If required, you can add a note explaining why the file is being ignored by using the `--` separator.
@@ -95,7 +96,8 @@ $xmlPackage->send();
95
96
```
96
97
97
98
> [!NOTE]
98
-
> Before PHP_CodeSniffer version 3.2.0, use `// @codingStandardsIgnoreStart` instead of `// phpcs:disable`, and use `// @codingStandardsIgnoreEnd` instead of `// phpcs:enable`. The `@codingStandards` syntax is deprecated and will be removed in PHP_CodeSniffer version 4.0.
99
+
> Before PHP_CodeSniffer version 3.2.0, use `// @codingStandardsIgnoreStart` instead of `// phpcs:disable`, and use `// @codingStandardsIgnoreEnd` instead of `// phpcs:enable`.
100
+
> The `@codingStandards` syntax is deprecated and will be removed in PHP_CodeSniffer version 4.0.
99
101
100
102
If you don't want to disable all coding standard errors, you can selectively disable and re-enable specific error message codes, sniffs, categories of sniffs, or entire coding standards. The following example disables the specific `Generic.Commenting.Todo.Found` message and then re-enables all checks at the end.
101
103
@@ -141,7 +143,8 @@ bar($foo, false);
141
143
```
142
144
143
145
> [!NOTE]
144
-
> Before PHP_CodeSniffer version 3.2.0, use `// @codingStandardsIgnoreLine` instead of `// phpcs:ignore`. The `@codingStandards` syntax is deprecated and will be removed in PHP_CodeSniffer version 4.0.
146
+
> Before PHP_CodeSniffer version 3.2.0, use `// @codingStandardsIgnoreLine` instead of `// phpcs:ignore`.
147
+
> The `@codingStandards` syntax is deprecated and will be removed in PHP_CodeSniffer version 4.0.
145
148
146
149
Again, you can selectively ignore one or more specific error message codes, sniffs, categories of sniffs, or entire standards.
147
150
@@ -219,9 +222,9 @@ To show all errors, but only warnings with a severity of 8 or more:
Setting the severity of warnings to `0` is the same as using the `-n` command line argument. If you set the severity of errors to `0` PHP_CodeSniffer will not show any errors, which may be useful if you just want to show warnings.
225
+
Setting the severity of warnings to `0` is the same as using the `-n` command line argument. If you set the severity of errors to `0`, PHP_CodeSniffer will not show any errors, which may be useful if you just want to show warnings.
223
226
224
-
This feature is particularly useful during manual code reviews. During normal development, or an automated build, you may want to only check code formatting issues. But while during a code review, you may wish to show less severe errors and warnings that may need manual peer review.
227
+
This feature is particularly useful during manual code reviews. During normal development, or an automated build, you may want to only check code formatting issues, while during a code review, you may wish to show less severe errors and warnings that may need manual peer review.
225
228
226
229
<palign="right"><ahref="#table-of-contents">back to top</a></p>
> The [included sniff](https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/src/Standards/Generic/Sniffs/WhiteSpace/DisallowTabIndentSniff.php) that enforces space indentation will still generate errors even if you have replaced tabs with spaces using the `--tab-width` setting. This sniff looks at the unmodified version of the code to check line indentation and so must be disabled in a [[custom ruleset.xml file|Annotated ruleset]] if you want to use tab indentation.
242
+
> The `Generic.WhiteSpace.DisallowTabIndent` and `Generic.WhiteSpace.DisallowSpaceIndent` sniffs, which enforce space or tab indentation respectively, will still generate errors, even if you have replaced tabs with spaces using the `--tab-width` setting. These sniffs looks at the unmodified version of the code to check line indentation.
243
+
> When using a [[custom ruleset.xml file|Annotated ruleset]], only enable one of these two sniffs, never both.
240
244
241
245
<palign="right"><ahref="#table-of-contents">back to top</a></p>
242
246
243
247
244
248
## Specifying an Encoding
245
249
246
250
By default, PHP_CodeSniffer will treat all source files as if they use UTF-8 encoding. If you need your source files to be processed using a specific encoding, you can specify the encoding using the `--encoding` command line argument.
PHP_CodeSniffer can optionally include one or more custom bootstrap files before beginning the run. Bootstrap files are included after command line arguments and rulesets have been parsed, and right before files begin to process. These custom files may be used to perform such taks as manipulating the internal settings of PHP_CodeSniffer that are not exposed through command line arguments. Multiple bootstrap files are seperated by commas.
Copy file name to clipboardExpand all lines: wiki/Usage.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -268,7 +268,7 @@ Processing OpeningBraceSameLineSniff.php [936 tokens in 123 lines]... DONE in 26
268
268
269
269
PHP_CodeSniffer can have multiple coding standards installed to allow a single installation to be used with multiple projects. When checking PHP code, PHP_CodeSniffer can be told which coding standard to use. This is done using the `--standard` command line argument.
270
270
271
-
The example below checks the `myfile.inc` file for violations of the _PEAR_ coding standard (installed by default).
271
+
The example below checks the `myfile.inc` file for violations against the _PEAR_ coding standard (installed by default).
272
272
273
273
```bash
274
274
$ phpcs --standard=PEAR /path/to/code/myfile.inc
@@ -303,7 +303,7 @@ The installed coding standards are MySource, PEAR, PSR1, PSR2, PSR12, Squiz and
303
303
304
304
## Listing Sniffs Inside a Coding Standard
305
305
306
-
PHP_CodeSniffer can print you a list of the sniffs that a coding standard includes by specifying the `-e` command line argument along with the `--standard` argument. This allows you to see what checks will be applied when you use a given standard.
306
+
PHP_CodeSniffer can print you a list of the sniffs that a coding standard includes by specifying the `-e`(="explain") command line argument along with the `--standard` argument. This allows you to see what checks will be applied when you use a given standard.
0 commit comments