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 · 8 comments
Closed

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

rodrigoprimo opened this issue Sep 28, 2016 · 8 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
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.

@geoffreyvanwyk
Copy link

@geoffreyvanwyk geoffreyvanwyk commented Nov 15, 2018

Put this at the top of the file:

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

@linaori
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
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
Copy link

@linaori linaori commented Dec 13, 2018

@jrfnl That seems to work, thanks!

@bkdotcom
Copy link
Contributor

@bkdotcom bkdotcom commented May 6, 2020

Now we just need the ability to do it at the class and method level
#2367

@tiagofrancafernandes
Copy link

@tiagofrancafernandes tiagofrancafernandes commented Feb 22, 2022

Put this at the top of the file:

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

Can you show a example?

@jrfnl
Copy link
Contributor

@jrfnl jrfnl commented Feb 22, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants