Create own ruleset for codesniffer PHPCS

89 Views Asked by At

I am trying to create my own ruleset for PHPCS extending the WordPress standard. My goal is to define that a opening brace starts as the same line as the function name.

    public function __construct() {

        self::$instance = $this;
    }

So I added this to my ruleset

    <rule ref="Squiz.Functions.MultiLineFunctionDeclaration">
        <properties>
            <property name="opening_brace" value="same"/>
            <property name="closing_brace" value="next_line"/>
            <severity>5</severity>
        </properties>
    </rule>

But the sniffer still shows me the error:

Opening brace should be on a new line (Squiz.Functions.MultiLineFunctionDeclaration.BraceOnSameLine)

I just found this codesnippet, but I have no idea how to find the correct propertynames. How do I get the correct rule + property and value?

1

There are 1 best solutions below

0
Przemek Hernik On

The best way for now is to check the source code of sniffs to find out property names or just check the docs. Squiz.Functions.MultiLineFunctionDeclaration doesn't have any properties to set so the code you proposed just won't work. You can use the following sniff to achieve what you need (ref).

<rule ref="Generic.Functions.OpeningFunctionBraceKernighanRitchie" />