Open Melindrea opened 10 years ago
This should be possible by using the grunt-newer plugin.
My use case is slightly different, but the goal seems to be the same; only run phpcs on changed files.
grunt-newer seems to make some assumptions about how other plugins work that grunt-phpcs does not follow, so it does not work at the moment, but I assume it would be easy to fix.
I've started looking into the grunt-newer conflict, there's some puzzling bugs at 1 hour in.
I've been thinking about the changes-since-git-commit use case as well, newer is good for incremental checks, but it's less complete if your goal is a pre-commit hook to make sure an entire change set is clean. This is especially true if you switch between branches as you work.
The partial answer is to use a duplicate of your target, specific to things like githooks, on the premise that once you start trying to commit your code you will keep working until it's perfect and push your commit. In that case when you next make changes they are theoretically toward a new commit. This still feels messy in the branch switching case.
For that purpose we might configure the newer cache a bit differently: options.cache
allows us to override the directory for the newer timestamps, so we could detect the current git branch and use that in the tail of the directory.
Neither of these allows us to ignore unstaged files. grunt-newer has an options.override.include
parameter that can be set to a callback that could invoke a git command.
In any case, I'll start by looking at grunt-phpcs with newer, some sort of "newer-git" seems like it should be a more general purpose work.
So, I have a fairly specific use case (though perhaps not completely rare): We have legacy code that does not conform to the style, so while we're working on fixing the files we want to only use PHPCS on files that have been changed.
I've implemented an ad-hoc version of PHPCS which names specific files using git diff
$(git diff --cached --name-only --diff-filter=ACMRTUXB)
, but it does not (for obvious reasons ...) seem to work with your grunt task.Have you considered some way to name files using a command, or to only run on changed files or anything like that?