SaschaGalley / grunt-phpcs

Grunt plugin for running PHP Code Sniffer.
MIT License
47 stars 25 forks source link

Validating single file with help of grunt-contrib-watch #33

Open pdrylo opened 9 years ago

pdrylo commented 9 years ago

Is it possible to run phpcs on changed files only?

I have tried the following inside Gruntfile.js, but it does not affect grunt-phpcs configuration at all:

grunt.event.on('watch', function (action, filepath) {
    grunt.config.set('phpcs.application.dir', [filepath]);
});

Cheers

rolandba commented 9 years ago

Hi,

if you want to modify config variables on the fly, you have to set

options: {
    spawn: false
}

in your watch section. That's the magic.

pdrylo commented 9 years ago

Thanks, it helped in some way with changing the value of phpcs.application.dir, but phpcs task is not executing anymore. Changing it back to spawn: true fixes it, but the problem persists. Any ideas?

Thanks in advance

rolandba commented 9 years ago

It should be working, my part of gruntfile is:

grunt.event.on('watch', function (action, filepath) { if (grunt.file.isMatch(grunt.config('watch.cs_strict.files'), filepath)) { grunt.config('phpcs.strict.dir', [filepath]); } });

Maybe just try to remove .set