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

--exclude sniffs fails in some cases #1619

Closed
davidfavor opened this issue Aug 18, 2017 · 4 comments
Closed

--exclude sniffs fails in some cases #1619

davidfavor opened this issue Aug 18, 2017 · 4 comments

Comments

@davidfavor
Copy link

davidfavor commented Aug 18, 2017

I have a client with many .html files. Some contain PHP (shudder) + some are plain HTML.

My goal is to ignore the Internal.NoCodeFound sniff to prune 1000s of related messages from the output.

Let me know if there's a way to do this.

Thanks.


Problem #1 - the NoCodeFound sniff seems to live outside ruleset.xml, so fails to show up as being registered.

# phpcs -vvv -s --extensions="php,html,inc,lib" -d xdebug.show_exception_trace=0 -p --standard=PSR2 --runtime-set testVersion 7.1  /sites/.../image_example14.html | grep NoCodeFound
 1 | WARNING | 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)

Problem #2 - usage message for --sniffs + --exclude are poorly documented, so I can only guess at correct syntax.

Be great to add Usage examples for both --sniffs + --exclude + their usage together, if they effect each other.

Using --exclude=Internal.NoCodeFound kills phpcs.

# phpcs -s --exclude="Internal.NoCodeFound" --extensions="php,html,inc,lib" -d xdebug.show_exception_trace=0 -p --standard=PSR2 --runtime-set testVersion 7.1  /sites/.../image_example14.html
PHP PHP_CodeSniffer\Exceptions\DeepExitException:  ERROR: The specified sniff code "Internal.NoCodeFound" is invalid

Run "phpcs --help" for usage information

 in /root/php-code-sniffer/PHP_CodeSniffer.git/src/Config.php on line 822
PHP Stack trace:
PHP   1. {main}() /root/php-code-sniffer/PHP_CodeSniffer.git/bin/phpcs:0
PHP   2. PHP_CodeSniffer\Runner->runPHPCS() /root/php-code-sniffer/PHP_CodeSniffer.git/bin/phpcs:18
PHP   3. PHP_CodeSniffer\Config->__construct() /root/php-code-sniffer/PHP_CodeSniffer.git/src/Runner.php:67
PHP   4. PHP_CodeSniffer\Config->setCommandLineValues() /root/php-code-sniffer/PHP_CodeSniffer.git/src/Config.php:330
PHP   5. PHP_CodeSniffer\Config->processLongArgument() /root/php-code-sniffer/PHP_CodeSniffer.git/src/Config.php:414
ERROR: The specified sniff code "Internal.NoCodeFound" is invalid

Run "phpcs --help" for usage information

Problem #3 - Pre-pending with any of the installed coding standards has no effect.

# phpcs -s --exclude="PSR2.Internal.NoCodeFound" --extensions="php,html,inc,lib" -d xdebug.show_exception_trace=0 -p --standard=PSR2 --runtime-set testVersion 7.1  /sites/.../image_example14.html
W


FILE: /sites/.../image_example14.html
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 1 | WARNING | 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)
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Time: 102ms; Memory: 4Mb

Problem #4 - Pre-pending with bogus coding standard name has no effect.

# phpcs -s --exclude="jumpingjackflash.Internal.NoCodeFound" --extensions="php,html,inc,lib" -d xdebug.show_exception_trace=0 -p --standard=PSR2 --runtime-set testVersion 7.1  /sites/.../image_example14.html
W


FILE: /sites/.../image_example14.html
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 1 | WARNING | 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)
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Time: 100ms; Memory: 4Mb
@gsherwood
Copy link
Member

Put this in your ruleset to turn that error off:

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

@davidfavor
Copy link
Author

Ah... So the --exclude=... option doesn't work.

Let me know if rulesets can be chained... In other words, rather than hacking an existing ruleset, can I create an additional ruleset which inherits from other rulesets, so future git pull invocations don't obliterate ruleset hacks.

Thanks.

@davidfavor
Copy link
Author

Ruleset mod above works like a champ.

Thanks.

Looks like PHP_CodeSniffer.git/src/Standards/PSR2 contains an example of chaining to PSR1, so I can likely figure out how.

Point me to the docs about this, if they exist.

Thanks.

@gsherwood
Copy link
Member

Point me to the docs about this, if they exist.

The ruleset.xml options are documented here: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml

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

No branches or pull requests

2 participants