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

phpcs:ignore usage unclear #2157

Closed
marcelloh opened this issue Sep 13, 2018 · 6 comments
Closed

phpcs:ignore usage unclear #2157

marcelloh opened this issue Sep 13, 2018 · 6 comments

Comments

@marcelloh
Copy link

The documentation only mentioned the way is is set,
but what I miss, is:
is it set only for that file, or method, or next line?
and how is it unset?

@jrfnl
Copy link
Contributor

jrfnl commented Sep 13, 2018

The PHPCS annotations are documented quite extensively in the wiki: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Advanced-Usage#ignoring-parts-of-a-file

You can also ignore a single line using the phpcs:ignore comment. This comment will ignore the line that the comment is on, and the following line.

Does that answer your question ?

@marcelloh
Copy link
Author

Again, you can selectively ignore one or more specific error message codes, sniffs, categories of sniffs, or entire standards.

Does this still applies to one single line?
(this part is unclear to me)

@jrfnl
Copy link
Contributor

jrfnl commented Sep 13, 2018

phpcs:ignore -> applies to the line the comment is on and the following line.
phpcs:disable -> applies from that point forward to the end of the file or till the next phpcs:enable - Also see #1986.
phpcs:enable -> (only after a disable) applies from that point forward to the end of the file.

All of these can be combined with (parts of) sniff codes and those, in that case, will be applied only for the parts of the file the phpcs:... annotation applies to.

phpcs:ignoreFile can not be combined with sniff codes and when set at the beginning of the file, will prevent the file from being tokenized (performance shortcut). Also see #1903.

phpcs:set can be used to change sniff properties in-line - mostly used for the unit test files -. Any changed property setting will be applied from that point forward for the rest of the file and all files after it. Also see #2126.

Does that clarify it ?

@marcelloh
Copy link
Author

yes (I asked because I didn't find that particular case in the documentation)
So I can safely assume:
// phpcs:ignore someSpecificSniff
// phpcs:ignore someOtherSniff
myBadCode('partly', true);
will both skip the 2 sniffs on the first PHP line that is followed (so not: the next line, but the next real PHP line)

@jrfnl
Copy link
Contributor

jrfnl commented Sep 13, 2018

No, it will not. It will literally skip the line it is on and the next line - not the next line of real PHP.

So, this will not work as expected:

// phpcs:ignore someSpecificSniff -- This will ignore the annotation line below for someSpecificSniff.
// phpcs:ignore someOtherSniff -- This will ignore the code line below for someOtherSniff.
myBadCode('partly', true);

However, this will work:

// phpcs:ignore someSpecificSniff,someOtherSniff -- Skipping the next line for both sniffs.
myBadCode('partly', true);

@marcelloh
Copy link
Author

clear enough, thanks for the explanation

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