skryukov / rubocop-gradual

Gradually improve your code with RuboCop
MIT License
36 stars 0 forks source link

Feature Request/Bug Fix: Can `--staged` exclude files that are being deleted? #26

Closed dmorgan-fa closed 4 months ago

dmorgan-fa commented 4 months ago

Hi, I've just started using rubocop-gradual and so far found it really useful, so thanks for creating and maintaining the gem!

One issue I ran into was on file deletion, rubocop-gradual --staged run's into a RuboCop error:

RuboCop Error: No such file or directory: [...]/file-that-I'm-deleteing.rb

I noticed that --staged is just shelling out git diff: https://github.com/skryukov/rubocop-gradual/blob/c6b8d7f28b5eee20483db2b427c0ab29ebfc7f88/lib/rubocop/gradual/git.rb#L17

So I reckon the simplest fix would be to use --diff-filter (docs):

`git diff --cached --name-only --diff-filter=d`.split("\n")  # excludes deleted files