Run Pylint for all Python files in a directory and all subdirectories

Just pass the directory name to the pylint command. To lint all files in ./server:

pylint ./server

Note that this requires the __init__.py file to exist in the target directory.


My one cent

find . -type f -name "*.py" | xargs pylint 

How does it work?

find finds all files ends with py and pass to xargs, xargs runs pylint command on each file.

NOTE: You can give any argument to pylint command as well.

EDIT:

According to doc we can use

  1. pylint mymodule.py

  2. pylint directory/mymodule.py

  3. pylint ./module

number 2 will work if the directory is a python package (i.e. has an __init__.py file or it is an implicit namespace package) or if the “directory” is in the python path.


To run Pylint on all code in Git version control,

pylint $(git ls-files '*.py')

This is very fast, as Git already knows the names of all of your files. It also works on macOS which lacks Bash 4, and also Windows. However it won't lint files that are very new and haven't been git added to the repos yet.

My thanks to national treasure Julia Evans for the git ls-files trick -- here's her original use case, automating workflows with "entr": https://jvns.ca/blog/2020/06/28/entr/


To run pylint on all *.py files in a directory and its subdirectories, you can run:

shopt -s globstar  # for Bash
pylint ./**/*.py