Skip to content

Commit 06616b3

Browse files
committed
Issue - lint all files in a directory pylint-dev#352
pylint can be run on directories as well now. All .py files are identified in the directory and pylint is executed on the those .py files.
1 parent b3f6242 commit 06616b3

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

pylint/lint.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import sys
3939
import tokenize
4040
import warnings
41+
import fnmatch
4142

4243
import six
4344

@@ -105,6 +106,13 @@ def _merge_stats(stats):
105106
merged['by_msg'] = by_msg
106107
return merged
107108

109+
def _explore_dir(filepat, top):
110+
file_names = []
111+
for (path, _, filelist) in os.walk(top):
112+
for name in fnmatch.filter(filelist, filepat):
113+
full_name = os.path.join(path, name)
114+
file_names.append(full_name)
115+
return file_names
108116

109117
@contextlib.contextmanager
110118
def _patch_sysmodules():
@@ -726,6 +734,18 @@ def check(self, files_or_modules):
726734
"""main checking entry: check a list of files or modules from their
727735
name.
728736
"""
737+
temp_files_or_modules = []
738+
739+
for file in files_or_modules:
740+
#If it is a directory, then fetch all files present inside it.
741+
if os.path.isdir(file):
742+
file_list = _explore_dir("*.py", file)
743+
temp_files_or_modules.extend(file_list)
744+
else:
745+
temp_files_or_modules.append(file)
746+
747+
files_or_modules = temp_files_or_modules
748+
729749
# initialize msgs_state now that all messages have been registered into
730750
# the store
731751
for msg in self.msgs_store.messages:

0 commit comments

Comments
 (0)