summaryrefslogtreecommitdiff
path: root/pylint
diff options
context:
space:
mode:
authorPierre Sassoulas <pierre.sassoulas@gmail.com>2021-06-14 15:18:46 +0200
committerPierre Sassoulas <pierre.sassoulas@gmail.com>2021-06-17 13:45:42 +0200
commitcbd3cc07515e21ed08000941dc4883c86e84e208 (patch)
tree8d5a777fbe7898ee2423a9b24c42bfa5c5706872 /pylint
parent4dfaddf58129f1718340bf3b513a0270fe749354 (diff)
downloadpylint-git-cbd3cc07515e21ed08000941dc4883c86e84e208.tar.gz
No crash on bad plugin provided in configuration file
Raise an error 'bad-plugin-value' instead. See #4555
Diffstat (limited to 'pylint')
-rw-r--r--pylint/lint/pylinter.py21
-rw-r--r--pylint/message/message_handler_mix_in.py16
-rw-r--r--pylint/reporters/text.py4
3 files changed, 33 insertions, 8 deletions
diff --git a/pylint/lint/pylinter.py b/pylint/lint/pylinter.py
index 46818fb83..67cd9bfd3 100644
--- a/pylint/lint/pylinter.py
+++ b/pylint/lint/pylinter.py
@@ -128,6 +128,11 @@ MSGS = {
"bad-option-value",
"Used when a bad value for an inline option is encountered.",
),
+ "E0013": (
+ "Plugin '%s' is impossible to load, is it installed ? ('%s')",
+ "bad-plugin-value",
+ "Used when a bad value is used in 'load-plugins'.",
+ ),
}
@@ -531,8 +536,11 @@ class PyLinter(
if modname in self._dynamic_plugins:
continue
self._dynamic_plugins.add(modname)
- module = astroid.modutils.load_module_from_name(modname)
- module.register(self)
+ try:
+ module = astroid.modutils.load_module_from_name(modname)
+ module.register(self)
+ except ModuleNotFoundError:
+ pass
def load_plugin_configuration(self):
"""Call the configuration hook for plugins
@@ -542,9 +550,12 @@ class PyLinter(
settings.
"""
for modname in self._dynamic_plugins:
- module = astroid.modutils.load_module_from_name(modname)
- if hasattr(module, "load_configuration"):
- module.load_configuration(self)
+ try:
+ module = astroid.modutils.load_module_from_name(modname)
+ if hasattr(module, "load_configuration"):
+ module.load_configuration(self)
+ except ModuleNotFoundError as e:
+ self.add_message("bad-plugin-value", args=(modname, e), line=0)
def _load_reporters(self) -> None:
sub_reporters = []
diff --git a/pylint/message/message_handler_mix_in.py b/pylint/message/message_handler_mix_in.py
index 5bd83992a..1b468eeb7 100644
--- a/pylint/message/message_handler_mix_in.py
+++ b/pylint/message/message_handler_mix_in.py
@@ -274,6 +274,17 @@ class MessagesHandlerMixIn:
# update stats
msg_cat = MSG_TYPES[message_definition.msgid[0]]
self.msg_status |= MSG_TYPES_STATUS[message_definition.msgid[0]]
+ if self.stats is None:
+ # pylint: disable=fixme
+ # TODO self.stats should make sense,
+ # class should make sense as soon as instantiated
+ # This is not true for Linter and Reporter at least
+ # pylint: enable=fixme
+ self.stats = {
+ msg_cat: 0,
+ "by_module": {self.current_name: {msg_cat: 0}},
+ "by_msg": {},
+ }
self.stats[msg_cat] += 1
self.stats["by_module"][self.current_name][msg_cat] += 1
try:
@@ -291,7 +302,10 @@ class MessagesHandlerMixIn:
else:
module, obj = get_module_and_frameid(node)
abspath = node.root().file
- path = abspath.replace(self.reporter.path_strip_prefix, "", 1)
+ if abspath is not None:
+ path = abspath.replace(self.reporter.path_strip_prefix, "", 1)
+ else:
+ path = "configuration"
# add the message
self.reporter.handle_message(
Message(
diff --git a/pylint/reporters/text.py b/pylint/reporters/text.py
index 8e796c294..66e8de914 100644
--- a/pylint/reporters/text.py
+++ b/pylint/reporters/text.py
@@ -133,10 +133,10 @@ class TextReporter(BaseReporter):
def __init__(self, output=None):
BaseReporter.__init__(self, output)
self._modules = set()
- self._template = None
+ self._template = self.line_format
def on_set_current_module(self, module, filepath):
- self._template = str(self.linter.config.msg_template or self.line_format)
+ self._template = str(self.linter.config.msg_template or self._template)
def write_message(self, msg):
"""Convenience method to write a formatted message with class default template"""