codingjoe / relint

Write your own linting rules using regular expressions.
MIT License
57 stars 12 forks source link

lint only changed or added files in pre-commit #6

Closed zaro0508 closed 5 years ago

zaro0508 commented 5 years ago

I would like to run this linter with pre-commit[1] and I only want to lint changed or newly added files. Is there a way to do that with the pre-commit framework?

[1] https://pre-commit.com

codingjoe commented 5 years ago

Hi @zaro0508 that is a very good question. In fact @anapaulagomes contributed that feature a while ago. There is a catch, it isn't too easy to setup. This is mainly because pre-commit only provides each hook with a list of filenames rather than the diff. BUT we there is help:

  1. install relint
  2. copy relint-pre-commit.sh
  3. Change your commit hook to:
    -   id: relint
        name: relint
        entry: relint-pre-commit.sh
        language: system

I hope this helps you. Let me know if you have any further questions.