squizlabs / PHP_CodeSniffer

PHP_CodeSniffer tokenizes PHP files and detects violations of a defined set of coding standards.
BSD 3-Clause "New" or "Revised" License
10.66k stars 1.48k forks source link

3.x - No Output #1502

Closed alanondra closed 7 years ago

alanondra commented 7 years ago

I've installed it with Composer:

composer require --dev squizlabs/php_codesniffer:3.*

And I'm trying to run it from my project's directory:

./vendor/bin/phpcs

I've got my configuration in phpcs.xml in the project directory (copied from another project where it works as expected).

Nothing I do gets a response. I can pass in any parameters, I can mangle the configuration file, and I can insert invalid formatting in my code. It just doesn't do anything.

jrfnl commented 7 years ago

Could you try running it with the -v command line option and post any relevant output you see ? It might help identify the problem more easily.

alanondra commented 7 years ago

It doesn't do anything.

jrfnl commented 7 years ago

Hmm... let's up the verbosity, could you try again with -vvv ?

alanondra commented 7 years ago

Still nothing.

jrfnl commented 7 years ago

Can you share the project phpcs.xml file you are using ?

alanondra commented 7 years ago
<?xml version="1.0"?>
<ruleset name="PSR2-AO">
    <description>PSR-2 with customizations</description>

    <file>src</file>

    <rule ref="PSR2">
        <exclude name="Generic.Files.LineLength"/>
        <exclude name="Generic.WhiteSpace.DisallowTabIndent"/>
        <exclude name="Generic.Files.EndFileNewline"/>
    </rule>

    <arg name="tab-width" value="4"/>
    <rule ref="Generic.WhiteSpace.DisallowSpaceIndent"/>
    <rule ref="Generic.WhiteSpace.ScopeIndent">
        <properties>
            <property name="indent" value="4"/>
            <property name="tabIndent" value="true"/>
        </properties>
    </rule>
</ruleset>
jrfnl commented 7 years ago

Just add-libbing here, but I've seen some quirks now and again with different OS-es and how the files to process get determined. Could you try changing this line:

    <file>src</file>

to something like:

    <file>./src</file>

(you may need to try some variations here, but I hope you get my drift)

alanondra commented 7 years ago

Still nothing.

jrfnl commented 7 years ago

Ok, let's try overruling that part of the ruleset from the command line for now, just to see if we can get some response at all, so please try running PHPCS like this:

./vendor/bin/phpcs .

(note the . at the end)

alanondra commented 7 years ago

I've tried that, I've tried giving it absurd options and arguments. I've also tried blanking the rule set, using invalid syntax, and invalid definitions. Nothing I do with it gives me any kind of response.

jrfnl commented 7 years ago

Pff.. maybe we need to take a step back ... something might have gone wrong with the connection during the composer update or something. Can you remove the package and pull it in again after that ?

alanondra commented 7 years ago

I've nuked my entire vendor directory a couple times.

jrfnl commented 7 years ago

Oh cricky... hmm.. I've run out of ideas for now.

Actually... one last thing I just thought of: have you also cleared the Composer cache when you nuked the vendor directory ? The cache is where Composer downloads the packages before installing and will pull them from again if asked for the same package again. AFAIK the cache is not in the vendor/ directory, so clearing that out might give you a proper clean start.

alanondra commented 7 years ago
rm -rf vendor
composer clear-cache
composer install
./vendor/bin/phpcs -vvv

Still nothing.

jrfnl commented 7 years ago

composer install <- is that missing a --dev somewhere ?

alanondra commented 7 years ago

The --dev flag is deprecated so development packages are installed by default. If it weren't installing I would've at least gotten the "no such file or directory" error.

jrfnl commented 7 years ago

Could you try just doing a ./vendor/bin/phpcs -i ? If that doesn't give any response, then something is really wrong with the installation, if it does give a response, it is the config in one way or the other.

Not a solution, but at the very least it might help to figure out in which direction to continue the trouble shooting.

alanondra commented 7 years ago

Also nothing.

gsherwood commented 7 years ago

Could you try cloning this repo directly and seeing if PHPCS is even working on your machine?

git clone https://github.com/squizlabs/PHP_CodeSniffer.git
cd PHP_CodeSniffer
php bin/phpcs -h

If that works, then maybe just try ./bin/phpcs -h and make sure it is picking up the right PHP install. If that work, I'd try php ./vendor/bin/phpcs -h back in your composer installed version and just see what happens. Yes, I'm clutching at straws.

alanondra commented 7 years ago

Doing a direct clone and running it as described works fine. When I run it in my project as an argument to php it just prints the contents inside the vendor/bin/phpcs file.

gsherwood commented 7 years ago

Does the content of your vendor/bin/phpcs file actually have PHP tags in there?

alanondra commented 7 years ago

No, it looks like it's a Bash script calling bin/phpcs inside the package which then registers the autoloader and fires up an instance of CodeSniffer. I've inserted die('test'); after each point that's supposed to run and found that it silently fails during instantiation of PHP_CodeSniffer\Runner.

alanondra commented 7 years ago

I ran try/catch around the PHP_CodeSniffer\Runner instantiation and found nothing. I registered an error handler before running it. An issue with my project's own Composer configuration was the culprit, it'd been trying to read from a file that didn't exist yet.

jrfnl commented 7 years ago

@alanondra Glad to hear you've found the cause. Enjoy using PHPCS!

rilwis commented 1 year ago

This bug happens to me today.

Here is my composer.json file:

{
    "name": "elightup/slim-seo-link-manager",
    "type": "wordpress-plugin",
    "repositories": [
        {
            "type": "git",
            "url": "git@github.com:elightup/plugin-updater.git"
        },
        {
            "type": "git",
            "url": "git@github.com:elightup/plugin-search.git"
        }
    ],
    "autoload": {
        "psr-4": {
            "SlimSEOPro\\LinkManager\\": "src/",
            "SlimSEO\\": "lib"
        }
    },
    "minimum-stability": "dev",
    "prefer-stable": true,
    "config": {
        "prepend-autoloader": false,
        "allow-plugins": {
            "dealerdirect/phpcodesniffer-composer-installer": true
        }
    },
    "extra": {
        "dev-files": {
            "elightup/plugin-updater": [
                "plugin-updater.php"
            ],
            "elightup/plugin-search": [
                "plugin-search.php"
            ],
            "elightup/*": [
                ".git/",
                ".gitignore",
                "composer.json",
                "phpcs.xml"
            ]
        }
    },
    "require": {
        "elightup/plugin-updater": "dev-master",
        "deliciousbrains/wp-background-processing": "^1.0",
        "voku/stop-words": "^2.0",
        "elightup/plugin-search": "dev-master"
    },
    "require-dev": {
        "dealerdirect/phpcodesniffer-composer-installer": "^1.0",
        "wp-coding-standards/wpcs": "dev-develop",
        "phpcompatibility/phpcompatibility-wp": "^2.1"
    }
}

Here is my phpcs.xml file:

<?xml version="1.0"?>
<ruleset name="eLightUp WordPress Coding Standards">
    <!-- See https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml -->
    <!-- See https://github.com/WordPress/WordPress-Coding-Standards -->
    <!-- See https://github.com/PHPCompatibility/PHPCompatibilityWP -->

    <!--
    #############################################################################
    COMMAND LINE ARGUMENTS
    https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml
    #############################################################################
    -->

    <!-- Pass some flags to PHPCS:
         p flag: Show progress of the run.
         s flag: Show sniff codes in all reports.
    -->
    <arg value="ps"/>

    <!-- Check up to 8 files simultaneously. -->
    <arg name="parallel" value="8"/>

    <!-- Check PHP files only. JavaScript and CSS files are checked separately using the @wordpress/scripts package. -->
    <arg name="extensions" value="php"/>

    <!-- Check all files in this directory and the directories below it. -->
    <file>.</file>

    <!-- Exclude patterns. -->
    <exclude-pattern>/vendor/*</exclude-pattern>
    <exclude-pattern>/tests/*</exclude-pattern>
    <exclude-pattern>/.github/*</exclude-pattern>

    <rule ref="WordPress">
        <!-- Use PSR-4 naming -->
        <exclude name="WordPress.Files.FileName.NotHyphenatedLowercase" />
        <exclude name="WordPress.Files.FileName.InvalidClassFileName" />

        <!-- Only comment when neccessary -->
        <exclude name="Squiz.Commenting.FileComment.Missing" />
        <exclude name="Squiz.Commenting.FileComment.MissingPackageTag" />
        <exclude name="Squiz.Commenting.ClassComment.Missing" />
        <exclude name="Squiz.Commenting.FunctionComment.Missing" />
        <exclude name="Squiz.Commenting.FunctionComment.MissingParamTag" />
        <exclude name="Squiz.Commenting.VariableComment.Missing" />
        <exclude name="Squiz.Commenting.InlineComment.InvalidEndChar" />

        <!-- Write shorter -->
        <exclude name="Universal.Arrays.DisallowShortArraySyntax.Found" />
        <exclude name="Generic.Arrays.DisallowShortArraySyntax.Found" />
        <exclude name="Generic.PHP.DisallowShortOpenTag.EchoFound" />
        <exclude name="Generic.Commenting.DocComment.SpacingBeforeTags" />
        <exclude name="Squiz.PHP.EmbeddedPhp.NoSemicolon" />
        <exclude name="WordPress.Classes.ClassInstantiation.MissingParenthesis" />
        <exclude name="Universal.Operators.DisallowShortTernary.Found" />
        <exclude name="WordPress.PHP.DisallowShortTernary.Found" />
        <exclude name="PSR12.Classes.ClassInstantiation.MissingParentheses" />

        <!-- Optional -->
        <exclude name="PEAR.Functions.FunctionCallSignature.ContentAfterOpenBracket" />
        <exclude name="PEAR.Functions.FunctionCallSignature.CloseBracketLine" />
        <exclude name="PEAR.Functions.FunctionCallSignature.MultipleArguments" />
        <exclude name="WordPress.PHP.YodaConditions.NotYoda" />
    </rule>

    <rule ref="Generic.Arrays.DisallowLongArraySyntax" />

    <!-- Set the minimum supported WP version. This is used by several sniffs.
         The minimum version set here should be in line with the minimum WP version
         as set in the "Requires at least" tag in the readme.txt file. -->
    <config name="minimum_supported_wp_version" value="5.9"/>

    <rule ref="WordPress.WP.I18n">
        <properties>
            <property name="text_domain" type="array">
                <element value="slim-seo-link-manager"/>
                <element value="slim-seo"/>
            </property>
        </properties>
    </rule>

    <rule ref="WordPress.NamingConventions.PrefixAllGlobals">
        <properties>
            <property name="prefixes" type="array">
                <element value="SlimSEOPro\LinkManager"/>
                <element value="SlimSEO"/>
                <element value="slim_seo_link_manager"/>
                <element value="slim_seo"/>
            </property>
        </properties>
    </rule>

    <!--
    #############################################################################
    USE THE PHPCompatibility RULESET
    #############################################################################
    -->
    <config name="testVersion" value="7.2-"/>
    <rule ref="PHPCompatibilityWP"/>
</ruleset>

When I run the following commands nothing is outputted in the console:

./vendor/bin/phpcs -v
./vendor/bin/phpcs -h
./vendor/bin/phpcs -p .

I also run them with variations like setting the --standard="phpcs.xml" or set the folder to ./src/, etc. - still no luck.

I tried to add some die to the vendor/squizlabs/php_codesniffer folder to debug, and found that the code stops at autoload.php file, on this line:

https://github.com/squizlabs/PHP_CodeSniffer/blob/master/autoload.php#L77

It seems to load Composer's autoload, and then stops.

I don't know how to debug further.

Please take a look.

Thanks

jrfnl commented 1 year ago

@rilwis Just a small point of order: this is a closed PR/issue. While people who were involved in this PR/issue may get to see your comment, it will be invisible to most everyone else.

You may want to open a new issue or a support question in the discussion forum.

rilwis commented 1 year ago

I thought it's better to reopen this issue. So I commented here.

It's ok to open a new issue. I'll do that.

Thanks