1

I use Pylint and run it via a pre-commit hook. It doesn't ignore my migrations folders. What should I add to the configuration?

repos:
  - repo: https://github.com/PyCQA/pylint
    rev: pylint-2.5.2
    hooks:
      - id: pylint
        name: pylint
        entry: pylint
        language: system
        types: [python]
        args:
        - --rcfile=./backend/.pylintrc
        - --load-plugins=pylint_django

And file .pylintrc:

[MASTER]
init-hook='import sys; sys.path.append("./backend")'
max-line-length=120
disable=
    missing-module-docstring,
    missing-function-docstring,
    missing-class-docstring,
    too-few-public-methods,
    no-self-use,
    fixme,
ignore=migrations
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Tatiana
  • 576
  • 1
  • 6
  • 23

1 Answers1

2

pre-commit passes filenames as positional arguments to hooks

this means that it is calling pylint as:

pylint path/to/filename.py path/to/migrations/filename.py ...

when you invoke pylint like this, it produces lint errors for any files on the commandline explicitly. the ignore setting is only used for pylint's recursion mode

the suggested fix is to exclude those files from pylint in your pre-commit configuration

note also your configuration has another problem:

  • you're using the repository based configuration, but then overriding the setting with a language: system hook so you're discarding the repository configuration entirely

putting that all together:

repos:
  - repo: local
    hooks:
      - id: pylint
        name: pylint
        entry: pylint
        language: system
        types: [python]
        exclude: ^migrations/
        args:
        - --rcfile=./backend/.pylintrc
        - --load-plugins=pylint_django

disclaimer: I am the author of pre-commit

anthony sottile
  • 61,815
  • 15
  • 148
  • 207
  • Thank you for the answer! It really make sense and should work. But I still have the same problem, maybe I should take a look on something else. – Tatiana Jan 15 '21 at 12:54
  • "it doesn't work" -- can you show some output? my first guess is that you don't have a a migrations folder but instead a `something/migrations` (and so the regex pattern I used in my example won't match) – anthony sottile Jan 15 '21 at 17:20
  • Yeah, I had problem with regex. Now it's fine, thank you! – Tatiana Jan 19 '21 at 14:13