summaryrefslogtreecommitdiff
path: root/pylint/lint
diff options
context:
space:
mode:
authorChristoph Blessing <33834216+cblessing24@users.noreply.github.com>2022-09-03 20:44:32 +0200
committerGitHub <noreply@github.com>2022-09-03 20:44:32 +0200
commitcd7761d4fcdf1d6d3ad19b34a426a7033b41cc1a (patch)
treea88a07aa0dcce02a022ca88d9350b91b99da54db /pylint/lint
parentdca04df3efae7bd0508cdf36ada9d0a3271fd4b9 (diff)
downloadpylint-git-cd7761d4fcdf1d6d3ad19b34a426a7033b41cc1a.tar.gz
Do not lint ignored file on stdin (#7220)
Previously pylint would lint a file passed on stdin even if the user meant to ignore the file. This commit fixes that issue. Co-authored-by: Daniƫl van Noord <13665637+DanielNoord@users.noreply.github.com>
Diffstat (limited to 'pylint/lint')
-rw-r--r--pylint/lint/pylinter.py17
1 files changed, 11 insertions, 6 deletions
diff --git a/pylint/lint/pylinter.py b/pylint/lint/pylinter.py
index 472b3b030..8fa47ffe8 100644
--- a/pylint/lint/pylinter.py
+++ b/pylint/lint/pylinter.py
@@ -660,9 +660,7 @@ class PyLinter(
# 3) Get all FileItems
with fix_import_path(files_or_modules):
if self.config.from_stdin:
- fileitems = iter(
- (self._get_file_descr_from_stdin(files_or_modules[0]),)
- )
+ fileitems = self._get_file_descr_from_stdin(files_or_modules[0])
data: str | None = _read_stdin()
else:
fileitems = self._iterate_file_descrs(files_or_modules)
@@ -817,14 +815,21 @@ class PyLinter(
for msgid, line, args in spurious_messages:
self.add_message(msgid, line, None, args)
- @staticmethod
- def _get_file_descr_from_stdin(filepath: str) -> FileItem:
+ def _get_file_descr_from_stdin(self, filepath: str) -> Iterator[FileItem]:
"""Return file description (tuple of module name, file path, base name) from
given file path.
This method is used for creating suitable file description for _check_files when the
source is standard input.
"""
+ if _is_ignored_file(
+ filepath,
+ self.config.ignore,
+ self.config.ignore_patterns,
+ self.config.ignore_paths,
+ ):
+ return
+
try:
# Note that this function does not really perform an
# __import__ but may raise an ImportError exception, which
@@ -833,7 +838,7 @@ class PyLinter(
except ImportError:
modname = os.path.splitext(os.path.basename(filepath))[0]
- return FileItem(modname, filepath, filepath)
+ yield FileItem(modname, filepath, filepath)
def _iterate_file_descrs(
self, files_or_modules: Sequence[str]