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: .github/CONTRIBUTING.md
+79-35Lines changed: 79 additions & 35 deletions
Original file line number
Diff line number
Diff line change
@@ -6,15 +6,18 @@ Thank you for your interest in contributing to PHP_CodeSniffer!
6
6
7
7
## Reporting Bugs
8
8
9
-
Please search the [open issues](https://github.com/PHPCSStandards/PHP_CodeSniffer/issues) to see if your issue has been reported already and if so, comment in that issue if you have additional information, instead of opening a new one.
9
+
Please search the [open issues](https://github.com/PHPCSStandards/PHP_CodeSniffer/issues) to see if your issue has been reported
10
+
already and if so, comment in that issue if you have additional information, instead of opening a new one.
10
11
11
12
Before reporting a bug, you should check what sniff an error is coming from.
12
13
Running `phpcs` with the `-s` flag will show the name of the sniff for each error.
13
14
14
-
If the error code starts with anything other than `Generic`, `MySource`, `PEAR`, `PSR1`, `PSR2`, `PSR12`, `Squiz` or `Zend`, the error is likely coming from an external PHP_CodeSniffer standard.
15
+
If the error code starts with anything other than `Generic`, `MySource`, `PEAR`, `PSR1`, `PSR2`, `PSR12`, `Squiz` or `Zend`,
16
+
the error is likely coming from an external PHP_CodeSniffer standard.
15
17
**Please report bugs for externally maintained sniffs to the appropriate repository.**
16
18
17
-
Bug reports containing a minimal code sample which can be used to reproduce the issue are highly appreciated as those are most easily actionable.
19
+
Bug reports containing a minimal code sample which can be used to reproduce the issue are highly appreciated as those are most
20
+
easily actionable.
18
21
19
22
:point_right: Reports which only include a _screenshot_ of the code will be closed without hesitation as not actionable.
20
23
@@ -24,14 +27,17 @@ Bug reports containing a minimal code sample which can be used to reproduce the
24
27
PHP_CodeSniffer is a developer tool and should generally not be used in a production environment.
25
28
26
29
Having said that, responsible disclosure of security issues is highly appreciated.
27
-
Issues can be reported privately to the maintainers by opening a [Security vulnerability report](https://github.com/PHPCSStandards/PHP_CodeSniffer/security/advisories/new).
30
+
Issues can be reported privately to the maintainers by opening a
Please read the [documentation in the wiki](https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki) before opening an issue with a support question.
36
+
Please read the [documentation in the wiki](https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki) before opening an issue
37
+
with a support question.
33
38
34
-
The [discussion forum](https://github.com/PHPCSStandards/PHP_CodeSniffer/discussions) or [StackOverflow](https://stackoverflow.com/questions/tagged/phpcodesniffer) are the appropriate places for support questions.
39
+
The [discussion forum](https://github.com/PHPCSStandards/PHP_CodeSniffer/discussions) or
40
+
[StackOverflow](https://stackoverflow.com/questions/tagged/phpcodesniffer) are the appropriate places for support questions.
35
41
36
42
37
43
## Contributing Without Writing Code
@@ -43,16 +49,19 @@ We welcome bug triage.
43
49
Bug triage is the action of verifying a reported bug is reproducible and is actually an issue.
44
50
This includes checking whether the bug is something which should be fixed in **_this_** repository.
45
51
46
-
To find bugs which need triage, look for issues and PRs with the ["Status: triage"](https://github.com/PHPCSStandards/PHP_CodeSniffer/labels/Status%3A%20triage) label.
52
+
To find bugs which need triage, look for issues and PRs with the
* Verify whether the bug is reproducible with the given information.
50
57
* Ask for additional information if it is not.
51
-
* If you find the issue is reported to the wrong repo, ask the reporter to report it to the correct external standard repo and suggest closing the issue.
58
+
* If you find the issue is reported to the wrong repo, ask the reporter to report it to the correct external standard repo
59
+
and suggest closing the issue.
52
60
53
61
Additionally, for older issues:
54
62
* Check whether an issue still exists or has been fixed in `master` since the issue was initially reported.
55
-
* If it has been fixed, document (in a comment) which commit/PR was responsible for fixing the issue and suggest closing the ticket.
63
+
* If it has been fixed, document (in a comment) which commit/PR was responsible for fixing the issue
64
+
and suggest closing the ticket.
56
65
57
66
58
67
### Testing Open Pull Requests
@@ -61,22 +70,27 @@ Testing pull requests to verify they fix the issue they are supposed to fix with
61
70
62
71
To get access to a PHPCS version which includes the patch from a pull request, you can:
63
72
* Either use a git clone of the PHP_CodeSniffer repository and check out the PR.
64
-
* Or download the PHAR file(s) for the PR, which is available from the [Test workflow](https://github.com/PHPCSStandards/PHP_CodeSniffer/actions/workflows/test.yml) as an artifact of the workflow run.
73
+
* Or download the PHAR file(s) for the PR, which is available from the
The PHAR files can be found on the summary page of the test workflow run for the PR.
66
77
If the workflow has not been run (yet), the PHAR artifact may not be available (yet).
67
78
68
79
#### Typical test tasks:
69
80
* Verify that the patch solves the originally reported problem.
70
81
* Verify that the tests added in the PR fail without the fix and pass with the fix.
71
82
* For a fix for false negatives: verify that the correct error message(s) are thrown by the patched code.
72
-
* Run the patched PHPCS version against real codebases to see if the fix creates any side effects (new false positives/false negatives).
83
+
* Run the patched PHPCS version against real codebases to see if the fix creates any side effects
84
+
(new false positives/false negatives).
73
85
74
86
75
87
### Writing sniff documentation
76
88
77
-
Sniffs in PHP_CodeSniffer should preferably be accompanied by documentation. There is currently still a lot of [documentation missing](https://github.com/PHPCSStandards/PHP_CodeSniffer/issues/148).
89
+
Sniffs in PHP_CodeSniffer should preferably be accompanied by documentation. There is currently still a lot of
Sniff documentation is provided via XML files in the standard's `Docs` directory and is available to end-users via the command-line and/or can be compiled into an HTML or Markdown file.
92
+
Sniff documentation is provided via XML files in the standard's `Docs` directory and is available to end-users
93
+
via the command-line and/or can be compiled into an HTML or Markdown file.
80
94
81
95
To see an example of some of the available documentation, run:
82
96
```bash
@@ -95,11 +109,13 @@ The XML files consist of several parts:
95
109
* The `title` attribute in the `<documentation>` tag should generally reflect the name of the sniff.
96
110
* Each XML file can contain multiple `<standard>` blocks.
97
111
* Each `<standard>` block can be accompanied by one or more `<code_comparison>` blocks.
98
-
* Each code comparison block should have two `<code>` blocks, the first one showing "valid" code, the second one showing "invalid" code.
112
+
* Each code comparison block should have two `<code>` blocks, the first one showing "valid" code, the second one
113
+
showing "invalid" code.
99
114
100
115
Some guidelines to get you started:
101
116
* Keep it as simple as possible.
102
-
* When a sniff shows multiple different errors/warnings, it is recommended to have a separate `<standard>` block for each error/warning.
117
+
* When a sniff shows multiple different errors/warnings, it is recommended to have a separate `<standard>` block
118
+
for each error/warning.
103
119
* The title of a "good" code sample (on the left) should start with `Valid:`.
104
120
* The title of a "bad" code sample (on the right) should start with `Invalid:`.
105
121
* Don't use example code which can be traced back to a specific project.
@@ -123,39 +139,52 @@ There are also tasks looking for contributions, which don't necessarily fall int
123
139
124
140
#### Issues marked with "Status: waiting for opinions"
125
141
126
-
Proposals for new features, proposals for (structural) changes to PHP_CodeSniffer itself or to the contributor workflow, will initially be marked with the ["Status: waiting for opinions"](https://github.com/PHPCSStandards/PHP_CodeSniffer/labels/Status%3A%20waiting%20for%20opinions) label.
142
+
Proposals for new features, proposals for (structural) changes to PHP_CodeSniffer itself or to the contributor workflow,
143
+
will initially be marked with the
144
+
["Status: waiting for opinions"](https://github.com/PHPCSStandards/PHP_CodeSniffer/labels/Status%3A%20waiting%20for%20opinions)
145
+
label.
127
146
128
147
This is an open invitation for interested parties to gather their thoughts about the issue and to leave their opinion.
129
148
130
-
> Kind request: If you don't have something to add to the discussion, but do want to indicate a positive or negative opinion on a topic, please add an emoji on the original post instead of leaving a comment.
149
+
> Kind request: If you don't have something to add to the discussion, but do want to indicate a positive or negative opinion
150
+
> on a topic, please add an emoji on the original post instead of leaving a comment.
131
151
132
152
#### Issues marked with "Status: needs investigation"
133
153
134
154
Sometimes an issue has been identified, but it has not yet been pinpointed what the exact cause of the problem is.
135
155
136
-
Other times, like with syntax changes in PHP itself, PHP_CodeSniffer _may_, or _may not_, handle them correctly and this will need verification.
156
+
Other times, like with syntax changes in PHP itself, PHP_CodeSniffer _may_, or _may not_, handle them correctly
157
+
and this will need verification.
137
158
138
-
Issues like these will be marked with the ["Status: needs investigation"](https://github.com/PHPCSStandards/PHP_CodeSniffer/labels/Status%3A%20needs%20investigation) and investigating those can be a good way to learn more about the source code of PHP_CodeSniffer.
and investigating those can be a good way to learn more about the source code of PHP_CodeSniffer.
139
162
140
163
#### Issues marked with "Status: help wanted"
141
164
142
-
If you don't know where to start, having a browse through issues marked with the ["Status: help wanted"](https://github.com/PHPCSStandards/PHP_CodeSniffer/labels/Status%3A%20help%20wanted) and/or the ["Status: good first issue"](https://github.com/PHPCSStandards/PHP_CodeSniffer/labels/Status%3A%20good%20first%20issue) labels.
165
+
If you don't know where to start, having a browse through issues marked with the
166
+
["Status: help wanted"](https://github.com/PHPCSStandards/PHP_CodeSniffer/labels/Status%3A%20help%20wanted) and/or the
167
+
["Status: good first issue"](https://github.com/PHPCSStandards/PHP_CodeSniffer/labels/Status%3A%20good%20first%20issue) labels.
143
168
144
169
145
170
## Contributing With Code
146
171
147
172
### Requesting/Submitting New Features
148
173
149
-
Ideally, start by [opening an issue](https://github.com/PHPCSStandards/PHP_CodeSniffer/issues/new/choose) to check whether the feature is something which is suitable to be included in PHP_CodeSniffer.
174
+
Ideally, start by [opening an issue](https://github.com/PHPCSStandards/PHP_CodeSniffer/issues/new/choose) to check whether
175
+
the feature is something which is suitable to be included in PHP_CodeSniffer.
150
176
151
177
It's possible that a feature may be rejected at an early stage, and it's better to find out before you write the code.
152
178
153
-
It is also good to discuss potential different implementation options ahead of time and get guidance for the preferred option from the maintainers.
179
+
It is also good to discuss potential different implementation options ahead of time and get guidance for the preferred option
180
+
from the maintainers.
154
181
155
-
Note: There may be an issue or PR open already. If so, please join the discussion in that issue or PR instead of opening a duplicate issue/PR.
182
+
Note: There may be an issue or PR open already. If so, please join the discussion in that issue or PR instead of opening
183
+
a duplicate issue/PR.
156
184
157
185
> Please note: Auto-fixers will only be accepted for "non-risky" sniffs.
158
-
> If a fixer could cause parse errors or a change in the behaviour of the scanned code, the fixer will **NOT** be accepted in PHP_CodeSniffer and may be better suited to an external standard.
186
+
> If a fixer could cause parse errors or a change in the behaviour of the scanned code, the fixer will **NOT** be accepted
187
+
> in PHP_CodeSniffer and may be better suited to an external standard.
159
188
160
189
161
190
### Getting started
@@ -168,7 +197,8 @@ Note: There may be an issue or PR open already. If so, please join the discussio
168
197
169
198
### While working on a patch
170
199
171
-
Please make sure your code conforms to the PHPCS coding standard, is covered by tests and that all the PHP_CodeSniffer unit tests still pass.
200
+
Please make sure your code conforms to the PHPCS coding standard, is covered by tests and that all the PHP_CodeSniffer
201
+
unit tests still pass.
172
202
173
203
Also, please make sure your code is compatible with the PHP_CodeSniffer minimum supported PHP version, PHP 5.4.
174
204
@@ -178,7 +208,8 @@ To help you with this, a number of convenience scripts are available:
178
208
*`composer cbf` will run the autofixers for code style violations.
179
209
*`composer test` will run the unit tests.
180
210
*`composer coverage` will run the unit tests with code coverage and show a text summary.
181
-
*`composer coverage-local` will run the unit tests with code coverage and generate an HTML coverage report, which will be placed in a `build/coverage-html` subdirectory.
211
+
*`composer coverage-local` will run the unit tests with code coverage and generate an HTML coverage report,
212
+
which will be placed in a `build/coverage-html` subdirectory.
182
213
*`composer build` will build the phpcs.phar and phpcbf.phar files.
183
214
184
215
N.B.: You can ignore any skipped tests as these are for external tools.
@@ -195,28 +226,39 @@ For example, for the sniff named `Generic.NamingConventions.ConstructorName`:
195
226
* The sniff lives in the `src/Standards/Generic/Sniffs/NamingConventions/` directory.
196
227
* The tests live in the `src/Standards/Generic/Tests/NamingConventions/` directory.
197
228
* The tests consist of two files:
198
-
-`src/Standards/Generic/Tests/NamingConventions/ConstructorNameUnitTest.inc` which is the test _case_ file containing code for the sniff to analyse.
199
-
-`src/Standards/Generic/Tests/NamingConventions/ConstructorNameUnitTest.php` which is the test file, containing two methods, `getErrorList()` and `getWarningList()`, which should each return an array with as the keys the line number in the test _case_ file and as the values the number of errors or warnings which are expected on each line.
200
-
Only lines on which errors/warnings are expected need to be included in the lists. All other lines will automatically be set to expect no errors and no warnings.
229
+
-`src/Standards/Generic/Tests/NamingConventions/ConstructorNameUnitTest.inc` which is the test _case_ file containing
230
+
code for the sniff to analyse.
231
+
-`src/Standards/Generic/Tests/NamingConventions/ConstructorNameUnitTest.php` which is the test file, containing two methods,
232
+
`getErrorList()` and `getWarningList()`, which should each return an array with as the keys the line number
233
+
in the test _case_ file and as the values the number of errors or warnings which are expected on each line.
234
+
Only lines on which errors/warnings are expected need to be included in the lists. All other lines will automatically
235
+
be set to expect no errors and no warnings.
201
236
202
237
#### Multiple test case files
203
238
204
-
At times, one test _case_ file is not enough, for instance when the sniff needs to behave differently depending on whether or code is namespaced or not, or when a sniff needs to check something at the top of a file.
239
+
At times, one test _case_ file is not enough, for instance when the sniff needs to behave differently depending on whether or code
240
+
is namespaced or not, or when a sniff needs to check something at the top of a file.
205
241
206
242
The test framework allows for multiple test _case_ files.
207
243
In that case, the files should be numbered and the number should be placed between the file name and the extension.
208
244
209
-
So for the above example, the `src/Standards/Generic/Tests/NamingConventions/ConstructorNameUnitTest.inc` would be renamed to `src/Standards/Generic/Tests/NamingConventions/ConstructorNameUnitTest.1.inc` and additional test case files should be numbered sequentially like `src/Standards/Generic/Tests/NamingConventions/ConstructorNameUnitTest.2.inc`, `src/Standards/Generic/Tests/NamingConventions/ConstructorNameUnitTest.3.inc` etc.
245
+
So for the above example, the `src/Standards/Generic/Tests/NamingConventions/ConstructorNameUnitTest.inc` would be renamed to
246
+
`src/Standards/Generic/Tests/NamingConventions/ConstructorNameUnitTest.1.inc` and additional test case files should be numbered
247
+
sequentially like `src/Standards/Generic/Tests/NamingConventions/ConstructorNameUnitTest.2.inc`,
248
+
`src/Standards/Generic/Tests/NamingConventions/ConstructorNameUnitTest.3.inc` etc.
210
249
211
-
The `getErrorList()` and the `getWarningList()` methods will receive an optional `$testFile=''` parameter with the file name of the file being scanned - `ConstructorNameUnitTest.2.inc` - and should return the appropriate array for each file.
250
+
The `getErrorList()` and the `getWarningList()` methods will receive an optional `$testFile=''` parameter with the file name
251
+
of the file being scanned - `ConstructorNameUnitTest.2.inc` - and should return the appropriate array for each file.
212
252
213
253
#### Testing fixers
214
254
215
255
If a sniff contains errors/warnings which can be auto-fixed, these fixers should also be tested.
216
256
217
257
This is done by adding a test _case_ file with an extra `.fixed` extension for each test _case_ file which expects fixes.
218
258
219
-
For example, if the above `Generic.NamingConventions.ConstructorName` would contain an auto-fixer, there should be an additional `src/Standards/Generic/Tests/NamingConventions/ConstructorNameUnitTest.inc.fixed` file containing the code as it is expected to be after the fixer has run.
259
+
For example, if the above `Generic.NamingConventions.ConstructorName` would contain an auto-fixer, there should be an
260
+
additional `src/Standards/Generic/Tests/NamingConventions/ConstructorNameUnitTest.inc.fixed` file containing the code
261
+
as it is expected to be after the fixer has run.
220
262
221
263
The test framework will compare the actual fixes made with the expected fixes and will fail the tests if these don't match.
222
264
@@ -226,7 +268,8 @@ Some guidelines for submitting pull requests (PRs) and improving the chance that
226
268
* Please keep your PR as small as possible, but no smaller than that.
227
269
If your change is complex, make sure you add a proper commit message explaining what you have done and why.
228
270
* Please clean up your branch before pulling your PR.
229
-
Small PRs using atomic, descriptive commits are hugely appreciated as it will make reviewing your changes easier for the maintainers.
271
+
Small PRs using atomic, descriptive commits are hugely appreciated as it will make reviewing your changes
272
+
easier for the maintainers.
230
273
* Only open your PR when you've finished work on it, and you are confident that it is ready for review.
231
274
* Please make sure your pull request passes all continuous integration checks.
232
275
PRs which are failing their CI checks will likely be ignored by the maintainers or closed.
@@ -237,4 +280,5 @@ However, the maintainers time is also valuable and often, more scarce, so please
237
280
238
281
## Licensing
239
282
240
-
By contributing code to this repository, you agree to license your code for use under the [BSD-3-Clause license](https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/licence.txt).
283
+
By contributing code to this repository, you agree to license your code for use under the
0 commit comments