Passing pylint parameters with git-pylint-commit-hook

by Raaisa (
PEP8 guidelines state ‘a code is read much more often than it is written’. Writing a clean code is as important as writing a working code and maintaining code cleanliness can get tough when ignored for long.

If you are a git user, a pylint fan and too lazy to run pylint manually each time, git-pylint-commit-hook might help.
As the name says, it’s a pre-commit git-hook for pylint. One can find other examples of git pylint hooks.
I worked with the library as it could be installed easily with pip. The documentation could be found here.
The documentation helped me setup the hook but I was stuck while passing some extra pylint parameters. Figured it out finally, thanks to google and here it is. I wanted to disable missing-docstring message for test files. If run directly via pylint this could be done by:

[code lang=text]
pylint –disable=missing-docstring


The git-pylint-commit-hook library says append –pylint-params PYLINT_PARAMS to your pre-commit file. A snip from the document:


For our case this translates to:

[code lang=text]
git-pylint-commit-hook –pylint-params='–disable=missing-docstring'


in the pre-commit file. Works for git-pylint-commit-hook V 2.1.1.

The latest version also supports .pylintrc. I tried adding the above pylint parameters through .pylintrc. Our example can be run by writing in the .pylintrc file:

[code lang=text]


Here no quotation marks are to be added but this example will give error,

[code lang=text]
Traceback (most recent call last):
File "/Users/raaisa/OneDrive/Elucidata/FluxPython/myenv/bin/git-pylint-commit-hook", line 69, in
File "/Users/raaisa/OneDrive/Elucidata/FluxPython/myenv/bin/git-pylint-commit-hook", line 62, in main
args.limit, args.pylint, args.pylintrc, args.pylint_params, args.suppress_report)
File "/Users/raaisa/OneDrive/Elucidata/FluxPython/myenv/lib/python2.7/site-packages/git_pylint_commit_hook/", line 177, in check_repo
pylint_params += ' ' + conf.get('pre-commit-hook', 'params')
TypeError: unsupported operand type(s) for +=: 'NoneType' and 'str'


if the pre-commit file has only the following statement:

[code lang=text]


This is probably a bug in the library. Till resolved try the following. Instead of just git-pylint-commit-hook, add –pylint-params to it:

[code lang=text]
git-pylint-commit-hook –pylint-params=’some_pylint_parameter’


It should work now. It will consider both pre-commit file parameters and .pylintrc parameters.
And last but not the least, you might not want to always run pylint when committing a code. There is always –no-verify for that!!

Vipul Jain Written by:

One Comment

  1. November 23, 2018

    That’s a knowing answer to a difficult question

Leave a Reply

Your email address will not be published. Required fields are marked *