JustBlackBird / gulp-phpcs

Gulp plugin for running PHP Code Sniffer
MIT License
47 stars 12 forks source link

Some weird issues #5

Closed endyjasmi closed 9 years ago

endyjasmi commented 9 years ago

I have encounter a weird issues.

Consider that I have the following gulp file:

var gulp = require('gulp'),
    path = require('path'),
    phpcs = require('gulp-phpcs');

var patterns = ['src/**/*.php'];

gulp.task('phpcs', function() {
    var binary = path.join('.', 'vendor', 'bin', 'phpcs'),
        options = {
            bin: binary,
            standard: 'psr2'
        };

    gulp.src(patterns)
        .pipe(phpcs(options))
        .pipe(phpcs.reporter('log'))
        .on('error', function(error) {
            console.log(error);
        });
});

And my directory structure are:

project-root/
-gulpfile.js
-src/
--Library.php
--Library/
---Component.php
---Component/
---SubComponent.php
-vendor/
--...

When I run gulp phpcs from project-root, everything seems to work fine.

When there are failed rules in Library.php at the first level directory, everything works as expected. The bash return log message.

When there are failed rules in 'Component.php` at the second level directory, everything work as expected.

But, when there are some failed rules in 'SubComponent.php` at the third level directory, the plugin doesn't seems to do anything. No error message was returned.

JustBlackBird commented 9 years ago

I cannot reproduce the problem.

Are you sure the SubComponet.php file has coding style violations? What is the result of ./vendor/bin/phpcs --standard=psr2 src/Library/Component/SubComponent.php console command?

By the way, in the tree you provide SubComponent.php is at the second level directory (not the third), but I believe it's just a typo.

endyjasmi commented 9 years ago

Sorry, I did not test the example. It did work in the example I provided.

The one I am having problem with is this project in the develop brach.

if you run gulp phpcs from the root by default, it will work as currently there are no error.

When you change src/Neo4j/Request.php to violate the psr2 format, in my case it is to remove the new line at the last line. It will return error as expected.

Problem happens when changes are made to src/Neo4j/Request/Statement.php or even src/Neo4j/Response/Result.php or any file at third level directory. Running gulp phpcs seems to return nothing as if it have no error.

Thanks in advance for the reply


Edit: Ok, I just found out that when I edit src/Laravel/Facades/Neo4j.php. It did work as expected. Not sure what is happening anymore.


Edit: After adding a gulp-filelog and piping it through, I found that gulp only run until 80 file before terminating the process.


Edit: Even after adding a pattern to exclude certain folder to bring down the file count to 64 and having phpcs run through all file (excluding those being excluded, of course), it still did not works.

JustBlackBird commented 9 years ago

I tried to debug the problem and got some wired results. Can you try to run the following gulp command on Neo4j repository?

var gulp = require('gulp'),
    filelog = require('gulp-filelog');

gulp.task('list', function() {
    gulp.src('src/Neo4j/Clause/**/*.php')
        .pipe(filelog())
        .on('error', function(error) {
            console.log(error);
        });
});

In my environment it outputs only 16 entities instead of all files in the directory.

endyjasmi commented 9 years ago

Yup, confirmed. It stopped after 16th file OptionalMatchClause.php

JustBlackBird commented 9 years ago

It seems that the problem is not related with gulp-phpcs. Moreover gulp seems to be broken.

After some searching I've found this issue https://github.com/isaacs/node-glob/issues/128. It can be somehow related with the problem, because glob module is used in gulp under the hood.

endyjasmi commented 9 years ago

Ok, nice find. Thanks for your time. For now, I'll just go back to grunt.

Thanks -Endy

JustBlackBird commented 9 years ago

You are welcome. I've opened an issue in the gulp queue: https://github.com/gulpjs/gulp/issues/777

JustBlackBird commented 9 years ago

@endyjasmi I've finally found the problem. Your gulp file is wrong. You must return files stream from gulp task to make it works. Thus the correct phpcs task for neo4j is:

gulp.task('phpcs', function() {
    var binary = path.join('.', 'vendor', 'bin', 'phpcs'),
    options = {
        bin: binary,
        standard: 'psr2'
    };
    return gulp.src(patterns)
        .pipe(phpcs(options))
        .pipe(phpcs.reporter('log'))
        .on('error', function(error) {
            console.log(error);
        });
});
endyjasmi commented 9 years ago

Wow,..works like magic...everything just works, just one more question, is it normal for it to run slow? Running phpcs --standard=psr2 src/ seems to be faster..

JustBlackBird commented 9 years ago

gulp-phpcs runs phpcs for each file in the stream. It slower than phpcs --standard=psr2 src/ but it follows the gulp way. One can change contents of .php files in stream before pass it to gulp-phpcs.