How to set a pylint score threshold?
Here's a way to access the pylint API it in Python. The following code should be saved to a file and executed with first argument to the script to be module/file to lint:
import sys
from pylint import lint
THRESHOLD = 5
if len(sys.argv) < 2:
raise ArgumentError("Module to evaluate needs to be the first argument")
run = lint.Run([sys.argv[1]], do_exit=False)
score = run.linter.stats['global_note']
if score < THRESHOLD:
sys.exit(1)
Since pylint 2.5.0 there is a new argument called --fail-under
that resolves this question without needing external tools or scripts.
In this example, pylint will exit with error when score is under 8:
pylint --fail-under=8 python_code.py
Install
> pip install pylint-fail-under
And you can check the threshold value as below
pylint-fail-under --fail_under=6.0 test_pylint_code.py (or path)
If the score is below 6.0 it returns a message
ERROR: score 5.3999999999999995 is less than fail-under value 6.0
Else it returns exit code 0.
Link to official documentation is https://pypi.org/project/pylint-fail-under/