Skip to content

PHPCS annotations: selective re-enabling not working as expected #1986

@jrfnl

Description

@jrfnl

Example code based on: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Advanced-Usage#ignoring-parts-of-a-file with some small adjustments to test this properly:

// phpcs:disable PEAR,Squiz.Arrays $foo = [1,2,3]; bar( $foo, true ); // phpcs:enable PEAR.Functions.FunctionCallSignature bar( $foo, true ); // phpcs:enable Squiz $foo = [1,2,3]; // phpcs:enable

When running PHPCS over this snippet using phpcs -p -s ./test.php --standard=PEAR,Squiz --ignore-annotations, I see the following errors (ignoring the filecomment related errors):

 4 | ERROR | [x] Array with multiple values cannot be declared on a single line | | (Squiz.Arrays.ArrayDeclaration.SingleLineNotAllowed) 5 | ERROR | [x] Space after opening parenthesis of function call prohibited | | (PEAR.Functions.FunctionCallSignature.SpaceAfterOpenBracket) 5 | ERROR | [x] Expected 0 spaces before closing bracket; 1 found | | (PEAR.Functions.FunctionCallSignature.SpaceBeforeCloseBracket) 7 | ERROR | [x] Space after opening parenthesis of function call prohibited | | (PEAR.Functions.FunctionCallSignature.SpaceAfterOpenBracket) 7 | ERROR | [x] Expected 0 spaces before closing bracket; 1 found | | (PEAR.Functions.FunctionCallSignature.SpaceBeforeCloseBracket) 9 | ERROR | [x] Array with multiple values cannot be declared on a single line | | (Squiz.Arrays.ArrayDeclaration.SingleLineNotAllowed) 

If I repeat this without the --ignore-annotations, I only see the file comment errors, while I would expect to see:

  • The PEAR.Functions.FunctionCallSignature errors on line 7
  • The Squiz.Arrays.ArrayDeclaration error on line 9

A cursory analysis gives me the impression that selective re-enabling only works when using the exact same "selection" as for the disabling, so:

// phpcs:disable PEAR.Functions.FunctionCallSignature,Squiz.Arrays $foo = [1,2,3]; bar( $foo, true ); // phpcs:enable PEAR.Functions.FunctionCallSignature bar( $foo, true ); // phpcs:enable Squiz.Arrays $foo = [1,2,3]; // phpcs:enable

... works as expected.

Using a higher/lower level Standard/Category/SniffName in the enable vs the disable command, seems to break the functionality which is in stark contrast to what the documentation suggests.

I've checked the above against various points in time between the 3.2.0 version and the current master, but it looks like this was never implemented as intended.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions