Search code examples
pythonpylintpre-commit-hookpre-commitpre-commit.com

How to display scores for meeting --fail-under requirement .py files in .py lint, while using pre-commit?


My current pylint configuration:

  1. Installed via pip (in requirements.txt).
  2. The .pre-commit-config.yaml:
  - repo: local
    hooks:
        name: pylint
        entry: pylint
        language: system
        types: [ python ]
        files: ^src/
        args:
          [
              "-rn", # display messages
              "--rcfile=.pylintrc",
              "--fail-under=8.5"
          ]
  1. Execution method:
    source venv/bin/activate &&\
    pip freeze &&\
    pre-commit install &&\
    pre-commit run --all-files

When all .py files receive score higher than 8.5 then pylint is just passing and do not displaying any message. Is there any method to see all of the communicates even if --fail-under is met? (so we know what some is wrong with the files)


Solution

  • there is a setting which will force the output to always display: verbose: true but it is only intended for debug purposes as it tends to make the output noisy and your contributors will be likely to mentally filter it out as warning noise

    using your example:

      - repo: local
        hooks:
            name: pylint
            entry: pylint
            language: system
            types: [ python ]
            files: ^src/
            args:
              [
                  "-rn", # display messages
                  "--rcfile=.pylintrc",
                  "--fail-under=8.5"
              ]
            verbose: true
    

    unrelated, but there's no reason to use args for a repo: local hook since nothing can override it, you can specify those directly in entry:

        entry: pylint --rn --rcfile=.pylintrc --fail-under=8.5
    

    disclaimer: I created pre-commit