Php_codesniffer: Question: is there any way of completely preventing `Internal.NoCodeFound` even with `-s`?

Created on 2 Aug 2017  路  6Comments  路  Source: squizlabs/PHP_CodeSniffer

  • Is there any way of completely preventing Internal.NoCodeFound from being reported even when the -s flag is present?
Question

Most helpful comment

You need to use a ruleset.xml file, but you can then include this in it:

<rule ref="Internal.NoCodeFound">
    <severity>0</severity>
</rule>

All 6 comments

You need to use a ruleset.xml file, but you can then include this in it:

<rule ref="Internal.NoCodeFound">
    <severity>0</severity>
</rule>

I have this but using -s still returns this output in my report:

No PHP code was found in this file and short open tags are
not allowed by this install of PHP. This file may be using
short open tags but PHP does not allow them.
(Internal.NoCodeFound)

I was hoping to exclude this output/rule entirely even when using -s.

The -s option doesn't inject new errors into the output of PHPCS. It just prints the codes for each error found. I have tested this with a custom standard I have that hides the Internal.NoCodeFound error and it is working correctly.

Try running PHPCS with the -vv CLI arg (with an without the -s arg) and checking the top of the output. This will show what ruleset is being used and how it is being parsed. In both cases, you should see something like this:

Processing rule "Internal.NoCodeFound"
    * ignoring internal sniff code *
    => severity set to 0

Thanks for the info

This is the command I am running:

phpcs -s --ignore=*/vendor/* --extensions=php --report-file="phpcs-report.txt" --standard="C:/CustomPHPCS" .

I find the -s flag quite useful for indicating the rule/sniff that corresponds to the issue logged in my report. However, if by default Internal.NoCodeFound will always be included (when -s is present) then I guess I will have to drop using it.

What I was trying to say in my last comment is that the -s command line argument should not have any impact on what errors are reported by PHPCS. All it does is change the way the reports print themselves so they also print the error code next to the error message.

I have tested this with a ruleset that hides Internal.NoCodeFound and it is working correctly for me. I have also tested this with and without caching on, and using a report file or screen output. All cases are working for me.

There is no reason why the -s option should be changing the behaviour of your PHPCS run, which is why I asked if you could run PHPCS with the -vv command line argument to see if the ruleset is being processed correctly. You might also like to run phpcs with the --no-cache argument just to make sure something hasn't been incorrectly cached.

Thank you for getting back to me and giving me a thorough answer - appreciate it.

All sorted on my end and as you state, PHPCS is working exactly as it should be.

Was this page helpful?
0 / 5 - 0 ratings