Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to allow linting over all files #4217

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Release date: TBA
..
Put new features here

* Add option to allow linting for all files in and under a directory

* Introduce logic for checking deprecated attributes in DeprecationMixin.


Expand Down
6 changes: 6 additions & 0 deletions doc/whatsnew/2.8.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,9 @@ New checkers

Other Changes
=============

* Add option to allow linting for all files in and under a directory.

To expand linting beyond traditional and namespace packages, ``--lint-all`` was added
as a new flag to enable linting over all files in and under a directory. Unless activated,
it will not alter pylint current behavior to process only traditional and namespace packages.
14 changes: 13 additions & 1 deletion pylint/lint/pylinter.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,15 @@ def make_options():
),
},
),
(
"lint-all",
{
"type": "yn",
"metavar": "<yn>",
"default": False,
"help": ("Allow linting for all files in and under a directory."),
},
),
)

option_groups = (
Expand Down Expand Up @@ -957,7 +966,10 @@ def _iterate_file_descrs(self, files_or_modules):
def _expand_files(self, modules):
"""get modules and errors from a list of modules and handle errors"""
result, errors = utils.expand_modules(
modules, self.config.black_list, self.config.black_list_re
modules,
self.config.black_list,
self.config.black_list_re,
self.config.lint_all,
)
for error in errors:
message = modname = error["mod"]
Expand Down
10 changes: 6 additions & 4 deletions pylint/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def get_python_path(filepath):
return None


def expand_modules(files_or_modules, black_list, black_list_re):
def expand_modules(files_or_modules, black_list, black_list_re, lint_all):
"""take a list of files/modules/packages and return the list of tuple
(file, module name) which have to be actually checked
"""
Expand Down Expand Up @@ -194,7 +194,7 @@ def expand_modules(files_or_modules, black_list, black_list_re):
is_namespace = modutils.is_namespace(spec)
is_directory = modutils.is_directory(spec)

if not is_namespace:
if not is_namespace and (os.path.isfile(filepath) or not lint_all):
result.append(
{
"path": filepath,
Expand All @@ -211,7 +211,9 @@ def expand_modules(files_or_modules, black_list, black_list_re):
)
if has_init or is_namespace or is_directory:
for subfilepath in modutils.get_module_files(
os.path.dirname(filepath), black_list, list_all=is_namespace
os.path.dirname(filepath),
black_list,
is_namespace or lint_all,
):
if filepath == subfilepath:
continue
Expand All @@ -221,7 +223,7 @@ def expand_modules(files_or_modules, black_list, black_list_re):
continue

modpath = _modpath_from_file(
subfilepath, is_namespace, path=additional_search_path
subfilepath, is_namespace or lint_all, path=additional_search_path
)
submodname = ".".join(modpath)
result.append(
Expand Down
Empty file.
Empty file.
12 changes: 12 additions & 0 deletions tests/test_self.py
Original file line number Diff line number Diff line change
Expand Up @@ -918,3 +918,15 @@ def test_regression_parallel_mode_without_filepath(self):
HERE, "regrtest_data", "regression_missing_init_3564", "subdirectory/"
)
self._test_output([path, "-j2"], expected_output="No such file or directory")

def test_regression_lint_all(self):
self._test_output(
[join(HERE, "regrtest_data", "directory", "subdirectory"), "--lint-all=n"],
expected_output="No such file or directory",
)

def test_lint_all(self):
self._runtest(
[join(HERE, "regrtest_data", "directory", "subdirectory"), "--lint-all=y"],
code=0,
)