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

Normalize path before checking if path should be ignored #7080

Merged
Merged
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
5 changes: 5 additions & 0 deletions doc/whatsnew/2/2.14/full.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ What's New in Pylint 2.14.4?
----------------------------
Release date: TBA

* Fixed an issue where scanning `.` directory recursively with ``--ignore-path=^path/to/dir`` is not
ignoring the `path/to/dir` directory.

Closes #6964

* Fixed regression that didn't allow quoted ``init-hooks`` in option files.

Closes #7006
Expand Down
1 change: 1 addition & 0 deletions pylint/lint/expand_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def _is_ignored_file(
ignore_list_re: list[Pattern[str]],
ignore_list_paths_re: list[Pattern[str]],
) -> bool:
element = os.path.normpath(element)
basename = os.path.basename(element)
Pierre-Sassoulas marked this conversation as resolved.
Show resolved Hide resolved
return (
basename in ignore_list
Expand Down
21 changes: 21 additions & 0 deletions tests/test_self.py
Original file line number Diff line number Diff line change
Expand Up @@ -1330,6 +1330,27 @@ def test_recursive_current_dir(self):
code=0,
)

def test_ignore_path_recursive_current_dir(self) -> None:
"""Tests that path is normalized before checked that is ignored. GitHub issue #6964"""
with _test_sys_path():
# pytest is including directory HERE/regrtest_data to sys.path which causes
# astroid to believe that directory is a package.
sys.path = [
path
for path in sys.path
if not os.path.basename(path) == "regrtest_data"
]
with _test_cwd():
os.chdir(join(HERE, "regrtest_data", "directory"))
self._runtest(
[
".",
"--recursive=y",
"--ignore-paths=^ignored_subdirectory/.*",
],
code=0,
)

def test_regression_recursive_current_dir(self):
with _test_sys_path():
# pytest is including directory HERE/regrtest_data to sys.path which causes
Expand Down