summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre Sassoulas <pierre.sassoulas@gmail.com>2021-12-20 10:23:43 +0100
committerGitHub <noreply@github.com>2021-12-20 10:23:43 +0100
commitcdb57a8bfef91df7771c339b95931184f81ef940 (patch)
treee8b168e3429e2d132664b5670bd879e0173beb17
parent4f95e4d1db7bebe62aca1b757a54370b2546a33f (diff)
downloadpylint-git-cdb57a8bfef91df7771c339b95931184f81ef940.tar.gz
Ignore files with name that starts like an emacs lock files (#5554)
* Fix 'path' shadowing variable from outer scope * Ignore file that starts like emacs's file lock Closes #367 Co-authored-by: Daniƫl van Noord <13665637+DanielNoord@users.noreply.github.com>
-rw-r--r--ChangeLog7
-rw-r--r--doc/whatsnew/2.13.rst8
-rw-r--r--pylint/lint/expand_modules.py4
-rw-r--r--pylint/lint/pylinter.py5
-rw-r--r--pylint/testutils/configuration_test.py13
-rw-r--r--pylint/utils/linterstats.py2
-rw-r--r--tests/functional/e/.#emacs_file_lock.py4
-rw-r--r--tests/functional/e/.#emacs_file_lock_by_conf.py3
-rw-r--r--tests/functional/e/.#emacs_file_lock_by_conf.rc2
-rw-r--r--tests/functional/e/.#emacs_file_lock_redefined_conf.py3
-rw-r--r--tests/functional/e/.#emacs_file_lock_redefined_conf.rc2
-rw-r--r--tests/functional/e/.#emacs_file_lock_redefined_conf.txt1
12 files changed, 47 insertions, 7 deletions
diff --git a/ChangeLog b/ChangeLog
index 5f9508643..128ae03af 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -30,6 +30,13 @@ Release date: TBA
Closes #5499
+* By default, pylint does no longer take files starting with ``.#`` into account. Those are
+ considered `emacs file locks`. See
+ https://www.gnu.org/software/emacs/manual/html_node/elisp/File-Locks.html.
+ This behavior can be reverted by redefining the ``ignore-patterns`` option.
+
+ Closes #367
+
* ``used-before-assignment`` now assumes that assignments in except blocks
may not have occurred and warns accordingly.
diff --git a/doc/whatsnew/2.13.rst b/doc/whatsnew/2.13.rst
index 357f78b59..5e5d73493 100644
--- a/doc/whatsnew/2.13.rst
+++ b/doc/whatsnew/2.13.rst
@@ -32,6 +32,14 @@ Extensions
Other Changes
=============
+* By default, pylint does no longer take files starting with ``.#`` into account. Those are
+ considered `emacs file locks`_. This behavior can be reverted by redefining the
+ ``ignore-patterns`` option.
+
+ Closes #367
+
+.. _`emacs file locks`: https://www.gnu.org/software/emacs/manual/html_node/elisp/File-Locks.html
+
* Fixed extremely long processing of long lines with comma's.
Closes #5483
diff --git a/pylint/lint/expand_modules.py b/pylint/lint/expand_modules.py
index 8eaf98847..7a0dc7004 100644
--- a/pylint/lint/expand_modules.py
+++ b/pylint/lint/expand_modules.py
@@ -8,8 +8,8 @@ from pylint.typing import ErrorDescriptionDict, ModuleDescriptionDict
def _modpath_from_file(filename, is_namespace, path=None):
- def _is_package_cb(path, parts):
- return modutils.check_modpath_has_init(path, parts) or is_namespace
+ def _is_package_cb(inner_path, parts):
+ return modutils.check_modpath_has_init(inner_path, parts) or is_namespace
return modutils.modpath_from_file_with_callback(
filename, path=path, is_package_cb=_is_package_cb
diff --git a/pylint/lint/pylinter.py b/pylint/lint/pylinter.py
index ba310483c..bfeec152d 100644
--- a/pylint/lint/pylinter.py
+++ b/pylint/lint/pylinter.py
@@ -223,9 +223,10 @@ class PyLinter(
"type": "regexp_csv",
"metavar": "<pattern>[,<pattern>...]",
"dest": "black_list_re",
- "default": (),
+ "default": (r"^\.#",),
"help": "Files or directories matching the regex patterns are"
- " skipped. The regex matches against base names, not paths.",
+ " skipped. The regex matches against base names, not paths. The default value "
+ "ignores emacs file locks",
},
),
(
diff --git a/pylint/testutils/configuration_test.py b/pylint/testutils/configuration_test.py
index 809fd4eb5..d878fae76 100644
--- a/pylint/testutils/configuration_test.py
+++ b/pylint/testutils/configuration_test.py
@@ -5,11 +5,13 @@
import copy
import json
import logging
+import re
import unittest
from pathlib import Path
from typing import Any, Dict, List, Tuple, Union
from unittest.mock import Mock
+from pylint.constants import PY38_PLUS
from pylint.lint import Run
# We use Any in this typing because the configuration contains real objects and constants
@@ -18,6 +20,13 @@ ConfigurationValue = Any
PylintConfiguration = Dict[str, ConfigurationValue]
+if not PY38_PLUS:
+ # We need to deepcopy a compiled regex pattern
+ # In python 3.6 and 3.7 this require a hack
+ # See https://stackoverflow.com/a/56935186
+ copy._deepcopy_dispatch[type(re.compile(""))] = lambda r, _: r # type: ignore[attr-defined]
+
+
def get_expected_or_default(
tested_configuration_file: Union[str, Path],
suffix: str,
@@ -31,7 +40,7 @@ def get_expected_or_default(
with open(expected_result_path, encoding="utf8") as f:
expected = f.read()
# logging is helpful to realize your file is not taken into
- # account after a misspell of the file name. The output of the
+ # account after a misspelling of the file name. The output of the
# program is checked during the test so printing messes with the result.
logging.info("%s exists.", expected_result_path)
else:
@@ -139,7 +148,7 @@ def run_using_a_configuration_file(
# would not be accessible outside the `with` block.
with unittest.mock.patch("sys.exit") as mocked_exit:
# Do not actually run checks, that could be slow. We don't mock
- # `Pylinter.check`: it calls `Pylinter.initialize` which is
+ # `PyLinter.check`: it calls `PyLinter.initialize` which is
# needed to properly set up messages inclusion/exclusion
# in `_msg_states`, used by `is_message_enabled`.
check = "pylint.lint.pylinter.check_parallel"
diff --git a/pylint/utils/linterstats.py b/pylint/utils/linterstats.py
index cb2085352..4a05c93df 100644
--- a/pylint/utils/linterstats.py
+++ b/pylint/utils/linterstats.py
@@ -155,7 +155,7 @@ class LinterStats:
{self.percent_duplicated_lines}"""
def init_single_module(self, module_name: str) -> None:
- """Use through Pylinter.set_current_module so Pyliner.current_name is consistent."""
+ """Use through PyLinter.set_current_module so PyLinter.current_name is consistent."""
self.by_module[module_name] = ModuleStats(
convention=0, error=0, fatal=0, info=0, refactor=0, statement=0, warning=0
)
diff --git a/tests/functional/e/.#emacs_file_lock.py b/tests/functional/e/.#emacs_file_lock.py
new file mode 100644
index 000000000..b2674f414
--- /dev/null
+++ b/tests/functional/e/.#emacs_file_lock.py
@@ -0,0 +1,4 @@
+# The name is invalid, but we should not analyse this file
+# Because its filename reseambles an emacs file lock ignored by default
+# https://www.gnu.org/software/emacs/manual/html_node/elisp/File-Locks.html
+# See https://github.com/PyCQA/pylint/issues/367
diff --git a/tests/functional/e/.#emacs_file_lock_by_conf.py b/tests/functional/e/.#emacs_file_lock_by_conf.py
new file mode 100644
index 000000000..151168cc8
--- /dev/null
+++ b/tests/functional/e/.#emacs_file_lock_by_conf.py
@@ -0,0 +1,3 @@
+# The name is invalid, but we should not analyse this file
+# Because it resembles an emacs file lock and is ignored by the configuration
+# See https://github.com/PyCQA/pylint/issues/367
diff --git a/tests/functional/e/.#emacs_file_lock_by_conf.rc b/tests/functional/e/.#emacs_file_lock_by_conf.rc
new file mode 100644
index 000000000..4140338cd
--- /dev/null
+++ b/tests/functional/e/.#emacs_file_lock_by_conf.rc
@@ -0,0 +1,2 @@
+[MASTER]
+ignore-patterns=^\.#
diff --git a/tests/functional/e/.#emacs_file_lock_redefined_conf.py b/tests/functional/e/.#emacs_file_lock_redefined_conf.py
new file mode 100644
index 000000000..4b26dee73
--- /dev/null
+++ b/tests/functional/e/.#emacs_file_lock_redefined_conf.py
@@ -0,0 +1,3 @@
+# [invalid-name]
+# The name is invalid and we should analyse this file
+# as ignore-patterns is redefined in the configuration
diff --git a/tests/functional/e/.#emacs_file_lock_redefined_conf.rc b/tests/functional/e/.#emacs_file_lock_redefined_conf.rc
new file mode 100644
index 000000000..76cd083fd
--- /dev/null
+++ b/tests/functional/e/.#emacs_file_lock_redefined_conf.rc
@@ -0,0 +1,2 @@
+[MASTER]
+ignore-patterns=""
diff --git a/tests/functional/e/.#emacs_file_lock_redefined_conf.txt b/tests/functional/e/.#emacs_file_lock_redefined_conf.txt
new file mode 100644
index 000000000..52050dcc8
--- /dev/null
+++ b/tests/functional/e/.#emacs_file_lock_redefined_conf.txt
@@ -0,0 +1 @@
+invalid-name:1:0:None:None::Module name "#emacs_file_lock_redefined_conf" doesn't conform to snake_case naming style:HIGH