Use PSR-2 with exceptions in PHP CodeSniffer

I'm trying to set up a rule set for PHP CodeSniffer to provide code style among the development team, but I ran into some problems.

We would like to stick with PSR-2, except for two things. We want class declarations to have an open bracket on the same line and the same for functions. The first thing I managed to fix, but the error for the open curly brace in one line for functions just won’t disappear.

I traced it to sniff Generic.Functions.OpeningFunctionBrace.BsdAllman and BraceOnSameLine errors, but adding this exception to my rule set does nothing.

My rule set is as follows:

<?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 the following:

 15 | ERROR | Opening brace should be on a new line 

This is my first attempt to create my own set of rules, and I'm really at a loss. I searched Google, searched and tried everything that seems.

+6
source share
2 answers

Found a problem. I got lost in what is included in the PSR2 rule set and ruled out the wrong things. Adding this solution:

 <exclude name="Squiz.Functions.MultiLineFunctionDeclaration.BraceOnSameLine"/> 
+6
source

Failover code is a way of using the -s symbol to show sniffing calls. for instance

 phpcs -s ugly.php 

Add results to exclude tags in the root phpcs.xml file of the project, for example, a demonstration

+1
source

Source: https://habr.com/ru/post/972174/


All Articles