JustBlackBird / gulp-phpcs

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

Run phpcs using the default configuration file #25

Closed iimog closed 8 years ago

iimog commented 8 years ago

It would be nice to have a way to run phpcs via gulp using a default configuration file. It would suffice for my use case to just call phpcs (at the given path) once without any arguments.

JustBlackBird commented 8 years ago

I'm not sure that config file follows the Gulp way. I've described my point in #24.

Nevertheless it seems that config file option is a wanted feature, so I'm not going to close this issue right now. I need some time to think more about the problem.

iimog commented 8 years ago

Sorry that I missed issue #24. I see that this would not really be the gulp way. And it is really great that everything can be configured in the gulpfile.

My use case is that I want to run all tasks with gulp. However other contributors might choose to run phpcs directly (or it might even be part of automatic code review e.g. codeclimate). I want to provide a single configuration such that no matter how phpcs is invoked the same configuration is used.

Thank you for considering this issue.

JustBlackBird commented 8 years ago

It seems that gulp-phpcs plugin is not actually necessary in your usecase.

You can specify all PHPCS settings in a config file then just run something like phpcs ./src/. from CLI. If so, the only thing you need is a common CLI task runner in your Gulp task. For example you can use something like this:

var exec = require('child_process').exec;

gulp.task('phpcs', function(cb) {
    exec('path_to_phpcs_bin', function(error, stdout, stderr) {
        if (error) {
            gulp.log(stderr);
            return cb(error);
        }
        cb();
    });
});

The task above does not follow gulp way (files are not in the stream), but you can think about it as an external CLI task.

If you still want to get all the benefits of gulp-phpcs you can try to specify your config file as the standard option (which is mapped to --standard flag). As for me it's just a hack but I cannot suggest you a better solution at the moment. Be aware, that all CLI options that are hard-coded in your config file will be used instead of values you specify in gulp-phpcs options.

iimog commented 8 years ago

Thank you very much for the detailed exlanation. Your solution works for me. I now use the standard option.

JustBlackBird commented 8 years ago

I'm closing the issue because there is no way to use config file besides one I've described above. At the same time I'm opened to new ideas here.

For now, let us consider passing path to config file through standard option as a feature and not as a dirty hack :smile: