Reputation: 772
I have added pylint to a client's project. Since the project is about 15 years old I would only like to lint the lines of code that have changed, making this a gradual process.
I tried the following command, however it shows errors from throughout the entire changed file. Is there a way to only report errors from lines of code that have actually been changed?
pylint `git diff --name-only --diff-filter=d | grep -E '\.py$' | tr '\n' ' '`
Upvotes: 1
Views: 2112
Reputation: 4282
Darker permits to do that. It supports black, isort, mypy, pylint, and flake8 in february 2021.
This utility reformats and checks Python source code files in a Git repository. However, it only applies reformatting and reports errors in regions which have changed in the Git working tree since the last commit.
Upvotes: 3
Reputation: 56
You could try lint_diffs package. Just passing it directly as in your example I think takes quite some configuring of pylint since it checks indentation and imports etc which is useless without context
To just get the diff in pure text you could use Michas answer
git diff --color=always|perl -wlne 'print $1 if /^\e\[32m\+\e\[m\e\[32m(.*)\e\[m$/'
And pipe it to pylint but you can't feed pure text to pylint since it wants modules or packages as input not raw code.
Upvotes: 0