RAbraham
RAbraham

Reputation: 6306

Rubocop only to check modified lines

I would like to run rubocop on the terminal only for the lines that I have modified within a git versioned project. Currently, from googling, I see scripts which work on the entire modified file.

I found this but what I understand from the documentation is that it shows false positives and negatives.

Upvotes: 12

Views: 5088

Answers (2)

Alexander
Alexander

Reputation: 485

As I can see there is no option to force Rubocop check some lines, it can only be scoped by files. But it's possible to filter Rubocop output to highlight only modified lines.

This will show Rubocop offences only for modified and unstaged files (in context of current Git repo):

rubocop $(git diff --name-only --diff-filter=d) | \
reviewdog -f=rubocop -diff="git diff" -fail-on-error -filter-mode="added"

It requires Reviewdog https://github.com/reviewdog/reviewdog#installation

Upvotes: 0

Dawid Gosławski
Dawid Gosławski

Reputation: 2088

Pronto is gem that can do that - install pronto and pronto-rubocop.

If you want you can use this gist https://gist.github.com/alkuzad/dd729aca36a810892772 that I've used a lot before I was using pronto (it's still handy because pronto is not so flexible about diff). You have to install showlinenum from https://github.com/jay/showlinenum to ~/bin to get it work (or just modify the path in gist)

Upvotes: 8

Related Questions