squizlabs / PHP_CodeSniffer

PHP_CodeSniffer tokenizes PHP files and detects violations of a defined set of coding standards.
BSD 3-Clause "New" or "Revised" License
10.66k stars 1.48k forks source link

ruleset.xml Modified messages require properties to be redeclaired #1040

Closed photodude closed 8 years ago

photodude commented 8 years ago

for tab based files, If you declare something like the following in the ruleset.xml:

    <arg name="tab-width" value="4"/>
    <rule ref="PEAR.Functions.FunctionDeclaration">
        <properties>
            <property name="indent" value="4"/>
        </properties>
        <exclude name="PEAR.Functions.FunctionDeclaration.CloseBracketLine" />
        <exclude name="PEAR.Functions.FunctionDeclaration.NewlineBeforeOpenBrace" />
    </rule>
    <rule ref="PEAR.Functions.FunctionDeclaration.Indent">
        <message>Multi-line function declaration not indented correctly; expected %s tabs but found %s</message>
    </rule>

PEAR.Functions.FunctionDeclaration.Indent will will throw errors

but if you declare something like this:

    <arg name="tab-width" value="4"/>
    <rule ref="PEAR.Functions.FunctionDeclaration">
        <properties>
            <property name="indent" value="4"/>
        </properties>
        <exclude name="PEAR.Functions.FunctionDeclaration.CloseBracketLine" />
        <exclude name="PEAR.Functions.FunctionDeclaration.NewlineBeforeOpenBrace" />
    </rule>
    <rule ref="PEAR.Functions.FunctionDeclaration.Indent">
        <properties>
            <property name="indent" value="4"/>
        </properties>
        <message>Multi-line function declaration not indented correctly; expected %s tabs but found %s</message>
    </rule>

you will not get errors

I feel it's little unexpected that I need to redeclare the <property name="indent" value="4"/> when changing a sniff message.

gsherwood commented 8 years ago

They both throw exactly the same errors for me, which is what I'd expect given the indent property wont be overwritten just by changing the message (or shouldn't be). Can you provide some code you are checking against that shows error?

photodude commented 8 years ago

I'm checking against this code and sub folders within the Joomla CMS project

gsherwood commented 8 years ago

I've used the ruleset you've provided and checked Joomla. I don't get any errors with either of the two ruleset snippets.

It might be worth you checking a single file, such as admin.php in that dir, and using the -vv command line argument so get more output. At the very top, you'll see how PHPCS is processing your ruleset. I get this:

Processing ruleset /Users/gsherwood/Sites/Projects/PHP_CodeSniffer/mystandard.xml
    Processing rule "PEAR.Functions.FunctionDeclaration"
        => /Users/gsherwood/Sites/Projects/PHP_CodeSniffer/CodeSniffer/Standards/PEAR/Sniffs/Functions/FunctionDeclarationSniff.php
        Excluding rule "PEAR.Functions.FunctionDeclaration.CloseBracketLine"
        => severity set to 0
        Excluding rule "PEAR.Functions.FunctionDeclaration.NewlineBeforeOpenBrace"
        => severity set to 0
        => property "indent" set to "4"
    Processing rule "PEAR.Functions.FunctionDeclaration.Indent"
        => /Users/gsherwood/Sites/Projects/PHP_CodeSniffer/CodeSniffer/Standards/PEAR/Sniffs/Functions/FunctionDeclarationSniff.php
        => message set to Multi-line function declaration not indented correctly; expected %s tabs but found %s
    => set command line value --tab-width=4
=> Ruleset processing complete; included 1 sniffs and excluded 0

You can see that it only sets the property value once, and it doesn't set it back. Do you get something different?

photodude commented 8 years ago

Ok, here is a file that I know the error should come up under.

Unfortunately, I am unable to reproduce this issue now. Could possibly be related to the other issues caused by failing to use --config-set tab_width 4 on tab based files

As I'm no longer able to reproduce the problem I'm closing the issue.