Skip to content

Commit 7c0f75f

Browse files
gsherwoodjrfnl
authored andcommitted
Documented new props for Generic.Formatting.SpaceAfterNot
1 parent 43c546f commit 7c0f75f

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

wiki/Customisable-Sniff-Properties.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ For more information about changing sniff behaviour by customising your ruleset,
1111
* [Generic.Files.LineEndings](#genericfileslineendings)
1212
* [Generic.Files.LineLength](#genericfileslinelength)
1313
* [Generic.Formatting.MultipleStatementAlignment](#genericformattingmultiplestatementalignment)
14+
* [Generic.Formatting.SpaceAfterNot](#genericformattingspaceafternot)
1415
* [Generic.Functions.OpeningFunctionBraceBsdAllman](#genericfunctionsopeningfunctionbracebsdallman)
1516
* [Generic.Functions.OpeningFunctionBraceKernighanRitchie](#genericfunctionsopeningfunctionbracekernighanritchie)
1617
* [Generic.Metrics.CyclomaticComplexity](#genericmetricscyclomaticcomplexity)
@@ -228,6 +229,55 @@ If the `error` property is set to `true`, an error will be thrown for violations
228229
</rule>
229230
```
230231

232+
### Generic.Formatting.SpaceAfterNot
233+
234+
Property Name | Type | Default | Available Since
235+
-------------- | ---- | ------- | ---------------
236+
spacing | int | 1 | 3.4.0
237+
ignoreNewlines | bool | false | 3.4.0
238+
239+
This sniff checks the spacing after a `!` operator. By default, the sniff ensures there is one space after the operator, as shown in the following code snippet:
240+
241+
```php
242+
if (! $foo) {
243+
}
244+
```
245+
246+
Another common way of using the `!` operator is to follow it with no space, as shown in the following code snippet:
247+
248+
```php
249+
if (!$foo) {
250+
}
251+
```
252+
253+
If you prefer to write your code like this, you can set the `spacing` property to `0`, or whatever padding you prefer.
254+
255+
```xml
256+
<rule ref="Generic.Formatting.SpaceAfterNot">
257+
<properties>
258+
<property name="spacing" value="0" />
259+
</properties>
260+
</rule>
261+
```
262+
263+
Sometimes complex statements are broken over multiple lines for readability, as shown in the following code snippet:
264+
```php
265+
if (!
266+
($foo || $bar)
267+
) {
268+
}
269+
```
270+
271+
By default, this sniff will generate an error if the `!` operator is followed by a newline. Setting the `ignoreNewlines` property to `true` will allow newline characters after a `!` operator.
272+
273+
```xml
274+
<rule ref="Generic.Formatting.SpaceAfterNot">
275+
<properties>
276+
<property name="ignoreNewlines" value="true" />
277+
</properties>
278+
</rule>
279+
```
280+
231281
### Generic.Functions.OpeningFunctionBraceBsdAllman
232282

233283
Property Name | Type | Default | Available Since

0 commit comments

Comments
 (0)