Skip to content

Commit

Permalink
Normalize path before checking if path should be ignored (pylint-dev#…
Browse files Browse the repository at this point in the history
…7080)

Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
  • Loading branch information
matusvalo and Pierre-Sassoulas committed Jun 29, 2022
1 parent b1ce818 commit e366fb9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
5 changes: 5 additions & 0 deletions doc/whatsnew/2/2.14/full.rst
Expand Up @@ -9,6 +9,11 @@ Release date: TBA

Closes #6950

* 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
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)
return (
basename in ignore_list
Expand Down
21 changes: 21 additions & 0 deletions tests/test_self.py
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

0 comments on commit e366fb9

Please sign in to comment.