For large project, to rubocop all files is quite slow and usually it is done by CI but not locally.
For local purpose, I expect there is an option I can rubocop modified files only. So I can scan all files changed by me but leave the all files rubocop at CI server.
I think that you can get the expected behavior with the following shell.
% git diff --name-only | xargs rubocop
I agree @koic's suggestion. Or you can use rubocop $(git diff --name-only).
RuboCop excepts non-ruby files that are received as command line arguments. So it works well if the diff has non-ruby files (e.g. when README.md is changed).
And I think we should not add an option for the problem to keep RuboCop simple.
Also, check out Pronto. It is focused on making PR comments, but I'm pretty sure you can just run it locally against the changes.
I think this question has come up before. If I remember correctly, the general consensus was although it might be nice to have, this isn't something we want to maintain in RuboCop itself. If we were to add support for git, we would also have to add support for all other version control systems.
The only change that I recommend adding to @koic's example is filter out deleted files git diff --name-only --diff-filter=MA. RuboCop will blow up if you try to pass in a file that does not exist.
Aside from "lint unpushed", I also use a "lint unmerged" to run RuboCop against all files that I have in a branch that have not been merged into master.
{ git diff HEAD --name-only --diff-filter=MA & git diff origin/master..HEAD --name-only --diff-filter=MA; } | sort | uniq
Use upstream instead of origin to lint files that haven't been merged into an upstream project.
{ git diff HEAD --name-only --diff-filter=MA & git diff upstream/master..HEAD --name-only --diff-filter=MA; } | sort | uniq
Closing as out of scope, with great alternative solutions by @koic 2nd @rrosenblum.
Most helpful comment
I think that you can get the expected behavior with the following shell.