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

SideEffectsSniff does not obey localised ignore annotations #327

Closed
andrewmatthews opened this issue Nov 25, 2014 · 3 comments
Closed

SideEffectsSniff does not obey localised ignore annotations #327

andrewmatthews opened this issue Nov 25, 2014 · 3 comments

Comments

@andrewmatthews
Copy link

It would be useful to ignore the SideEffectsSniff on certain files and/or lines.

A good example is a bootstrap file that sets INI values, includes files, defines constants, and declares functions/classes (autoloaders, etc).

@gsherwood
Copy link
Member

If you want to exclude, for example, a file called bootstrap.php, you can put this into your ruleset.xml file:

<rule ref="PSR1.Files.SideEffects">
    <exclude-pattern>*/bootstrap.php</exclude-pattern>
</rule>

This stops that specific sniff from running on files that match the exclude pattern. You can use a regular expression in there if you need to.

For this particular sniff, it doesn't make sense to ignore specific lines in a file because it is a whole-file sniff. It checks everything in the file and then reports 1 error, no matter how many side effects are found. So excluding the whole file is the best way to do things for this one.

Does that help solve your problem?

@andrewmatthews
Copy link
Author

That makes sense. I was looking for an annotation to exclude a specific sniff, but the XML will work.

Thanks for the quick response!

@gsherwood
Copy link
Member

From version 3.2, you'll be able to add the following comment to the top of your file to disable this sniff for a single file: // phpcs:disable PSR1.Files.SideEffects

See issue #604 for more details.

jrfnl added a commit to jrfnl/PHP_CodeSniffer that referenced this issue Jul 29, 2024
…b_actions/peter-evans/create-pull-request-6

GH Actions: Bump peter-evans/create-pull-request from 5 to 6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants