Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible to make PHPCS ignore one given rule for a particular file? #1179

Closed
rodrigoprimo opened this issue Sep 28, 2016 · 5 comments
Labels

Comments

@rodrigoprimo
Copy link

@rodrigoprimo rodrigoprimo commented Sep 28, 2016

I wonder if it is possible to make PHPCS ignore one given rule for a particular file or line of code? Sometimes for different reasons I have to use // @codingStandardsIgnoreLine but this will make PHPCS completely ignore the line.

As a example, I would like to be able to do something like // @codingStandardsIgnoreLine Generic.WhiteSpace.ScopeIndent to make PHPCS ignore just indentation for the line. Is there a way to do that?

@gsherwood

This comment has been minimized.

Copy link
Member

@gsherwood gsherwood commented Sep 28, 2016

There is no way to do this using annotations in your files. See issue #604 for a feature request.

You can add exclusions for entire files using a ruleset.xml file. See https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml for an example of hard-coding exclude patterns for specific sniffs. But you cannot do this for individual lines.

@gsherwood gsherwood closed this Sep 28, 2016
@gsherwood gsherwood added the Question label Sep 28, 2016
@systemovich

This comment has been minimized.

Copy link

@systemovich systemovich commented Nov 15, 2018

Put this at the top of the file:

// phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace

@linaori

This comment has been minimized.

Copy link

@linaori linaori commented Dec 13, 2018

@systemovich this does not work for me in combination with slevomat, it will either remove the comment or keep complaining. No other solution than to remove it for me.

@jrfnl

This comment has been minimized.

Copy link
Contributor

@jrfnl jrfnl commented Dec 13, 2018

@iltar Not sure about the details of your issue, but...

  1. You can add the annotation to a file docblock like so:
    <?php
    /**
     * File description
     *
     * @tags
     * @phpcs:disable Standard.Cat.SniffName
     */
  2. You can exclude a file for a particular rule or errorcode from a custom ruleset:
    <rule ref="Standard.Cat.SniffName.ErrorCode">
        <exclude-pattern>/path/to/file\.php</exclude-pattern>
    </rule>
@linaori

This comment has been minimized.

Copy link

@linaori linaori commented Dec 13, 2018

@jrfnl That seems to work, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.