I'm attempting to set up a ruleset for PHP CodeSniffer to enforce code style among a group of developers but I've run into some trouble.
We'd like to adhere to PSR-2 except for regarding two things. We want class declarations to have the open brace on the same line and the same for functions. The first I've managed to fix but the error for open brace on the same line for functions just will not go away.
I've traced it to the sniff Generic.Functions.OpeningFunctionBrace.BsdAllman and the error BraceOnSameLine but adding this exclude to my ruleset does nothing.
My ruleset looks like this:
<?xml version="1.0"?>
<ruleset name="OrgXYZ">
<description>The coding standard for Organization XYZ.</description>
<rule ref="PSR2">
<exclude name="PSR2.Classes.ClassDeclaration.OpenBraceNewLine"/>
<exclude name="Generic.Functions.OpeningFunctionBraceBsdAllman.BraceOnSameLine"/>
</rule>
</ruleset>
And the message I'm trying to remove from the report is this:
15 | ERROR | Opening brace should be on a new line
This is my first attempt at a ruleset of my own and I'm really at a loss here. I've googled, searched and tried everything it seems.
Found the problem. I'd gotten lost in what's included in the PSR2 ruleset and excluded the wrong things. Adding this solved it:
<exclude name="Squiz.Functions.MultiLineFunctionDeclaration.BraceOnSameLine"/>
The way to debug codesniffer, is to use the -s flag, revealing the sniffs invoked. For example
phpcs -s ugly.php
Add the results to exclude tags in your project root phpcs.xml, such as your demo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With