forked from iterative/dvc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpylint_plugin_disable.py
47 lines (37 loc) · 1.38 KB
/
pylint_plugin_disable.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"""
Disable certain checks for the tests.
To disable new checks, add to the `SUPPRESS_CHECKS` dictionary,
with `message_id` of the check to disable as a key and a list of
methods that check for that particular message.
"""
import os.path
from typing import TYPE_CHECKING
from pylint.checkers.base import NameChecker
from pylint.checkers.classes import ClassChecker
if TYPE_CHECKING:
from astroid import node_classes, scoped_nodes # noqa
from pylint.lint import PyLinter
TESTS_FOLDER = os.path.join(os.path.abspath(os.path.dirname(__file__)), "")
SUPPRESS_CHECKS = {
"protected-access": [
ClassChecker.visit_assign,
ClassChecker.visit_attribute,
],
"blacklisted-name": [
NameChecker.visit_global,
NameChecker.visit_assignname,
],
}
def is_node_in_tests(node: "node_classes.NodeNG"):
module: "scoped_nodes.Module" = node.root()
return module.file.startswith(TESTS_FOLDER)
def register(linter: "PyLinter"): # noqa
try:
from pylint_plugin_utils import suppress_message
except ImportError:
print("Cannot suppress message. 'pylint_plugin_utils' not installed.")
return
print("Registered custom plugin. Some checks will be disabled for tests.")
for msg, checks in SUPPRESS_CHECKS.items():
for checker_method in checks:
suppress_message(linter, checker_method, msg, is_node_in_tests)