Skip to content

Commit bb4e927

Browse files
authored
Merge pull request #16 from sirbrillig/add/sniff-codes-readme
Add sniff codes to README
2 parents 18ff2e2 + e75a6e6 commit bb4e927

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

README.md

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,46 @@ When installing sniff standards in a project, you edit a `phpcs.xml` file with t
4646
</ruleset>
4747
```
4848

49-
## Ignoring Symbols
49+
## Sniff Codes
50+
51+
There are two sniff codes that are reported by this sniff. Both are warnings.
52+
53+
- `ImportDetection.Imports.RequireImports.Symbol`: A symbol has been used but not imported
54+
- `ImportDetection.Imports.RequireImports.Import`: A symbol has been imported and not used
55+
56+
In any given file, you can use phpcs comments to disable these sniffs. For example, if you have a global class called `MyGlobalClass` which you don't want to import, you could use it like this:
57+
58+
```php
59+
<?php
60+
61+
$instance = new MyGlobalClass(); // phpcs:ignore ImportDetection.Imports.RequireImports.Symbol -- this class is global
62+
$instance->doSomething();
63+
```
64+
65+
For a whole file, you can ignore a sniff like this:
66+
67+
```php
68+
<?php
69+
// phpcs:disable ImportDetection.Imports.RequireImports.Symbol
70+
71+
$instance = new MyGlobalClass();
72+
$instance->doSomething();
73+
```
74+
75+
For a whole project, you can use the `phpcs.xml` file to disable these sniffs or modify their priority. For example, to disable checks for unused imports, you could use a configuration like this:
76+
77+
```xml
78+
<?xml version="1.0"?>
79+
<ruleset name="MyStandard">
80+
<description>My library.</description>
81+
<rule ref="ImportDetection"/>
82+
<rule ref="ImportDetection.Imports.RequireImports.Import">
83+
<severity>0</severity>
84+
</rule>
85+
</ruleset>
86+
```
87+
88+
## Ignoring Symbol Patterns
5089

5190
Oftentimes there might be global symbols that you want to use without importing or using a fully-qualified path.
5291

0 commit comments

Comments
 (0)