summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatus Valo <matusvalo@users.noreply.github.com>2022-06-28 23:10:04 +0200
committerGitHub <noreply@github.com>2022-06-28 23:10:04 +0200
commitc74493bdb969c40b0b9bc503b239c572ee31641b (patch)
treeaa40ad0e00159d560e46fb7925942658984183c6
parentc603f0e74972fd1edbc9d713cb917936a6a155de (diff)
downloadpylint-git-c74493bdb969c40b0b9bc503b239c572ee31641b.tar.gz
Normalize path before checking if path should be ignored (#7080)
Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
-rw-r--r--doc/whatsnew/2/2.14/full.rst5
-rw-r--r--pylint/lint/expand_modules.py1
-rw-r--r--tests/test_self.py21
3 files changed, 27 insertions, 0 deletions
diff --git a/doc/whatsnew/2/2.14/full.rst b/doc/whatsnew/2/2.14/full.rst
index 74177ea1e..861be5090 100644
--- a/doc/whatsnew/2/2.14/full.rst
+++ b/doc/whatsnew/2/2.14/full.rst
@@ -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
diff --git a/pylint/lint/expand_modules.py b/pylint/lint/expand_modules.py
index 5cacc0371..289e1afce 100644
--- a/pylint/lint/expand_modules.py
+++ b/pylint/lint/expand_modules.py
@@ -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
diff --git a/tests/test_self.py b/tests/test_self.py
index c18a04aef..d745161c5 100644
--- a/tests/test_self.py
+++ b/tests/test_self.py
@@ -1330,6 +1330,27 @@ class TestRunTC:
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