Just like we have "eslint --fix" to automatically fix lint problems in Javascript code, do we have something for pylint too for Python code?
Asked
Active
Viewed 5.0k times
49
-
11This is an old question, but voting to reopen as I don't really think it is seeking recommendations for books, tools, software libraries, etc; it's simply asking `pylint` has a way to automatically fix issues it finds- I was wondering the same thing and found this question. – Alexander Nied Apr 01 '21 at 19:26
-
Pylint (still) don't have the feature to auto fix, but today there are other alternatives like Ruff (id:charliermarsh.ruff) that can fix things. For an existing codebase with many lint errors, running for example Ruff can give you a running start in fixing all these errors. After that you can continue using Ruff, or switch to Pylint depending on your preferences. – Andreas Lundgren Jul 05 '23 at 06:09
3 Answers
20
Some of the formatting-errors reported by pylint
can be fixed with autopep8, black, or the built-in formatting supported by PyCharm and other IDEs.

erb
- 14,503
- 5
- 30
- 38

PythonUser
- 706
- 4
- 15
-
2Here is an example command using `autopep8`: `autopep8 --in-place --aggressive --aggressive *.py` – Tyler Chong Jan 03 '22 at 02:17
-
@TylerChong That example does not work in version 1.6.0 as it does not recognize *.py. Could you please provide an updated command that checks all files? – Dan Jul 30 '22 at 02:10
-
2autopep8 fixes only a small number of the errors reported by pylint. My code had a 1.95/10 rating after autopep8, with previous run at 0.39/10. – Lucas Gonze Sep 01 '22 at 00:15
-
AutoPep8 works well enough for me ( I am able to use the custom rules from the internal Google pylintrc file) from this link: https://google.github.io/styleguide/pyguide.html – Anshuman Kumar Feb 11 '23 at 11:57
5
You also have black now. Both black
and autopep8
can be integrated into most good editors.

NelsonGon
- 13,015
- 7
- 27
- 57

AntonOfTheWoods
- 809
- 13
- 17
-
2Unfortunately `black` fixes only a small number of the errors reported by `pylint`, even when combined with `autopep8`. – Serrano Sep 07 '22 at 06:23
-
Isn't Black highly opinionated? It would not work with a custom Pylintrc script, right? – Anshuman Kumar Feb 11 '23 at 09:04