summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pylint/config/option_manager_mixin.py5
-rw-r--r--pylint/lint/pylinter.py5
-rw-r--r--tests/config/functional/toml/issue_3181/toml_decode_error.1.out2
-rw-r--r--tests/config/functional/toml/issue_3181/toml_decode_error.toml3
-rw-r--r--tests/config/functional/toml/issue_3181/top_level_list_of_disable.out3
-rw-r--r--tests/config/functional/toml/issue_3181/top_level_list_of_disable.toml4
6 files changed, 21 insertions, 1 deletions
diff --git a/pylint/config/option_manager_mixin.py b/pylint/config/option_manager_mixin.py
index b43a3c27e..13938feae 100644
--- a/pylint/config/option_manager_mixin.py
+++ b/pylint/config/option_manager_mixin.py
@@ -274,7 +274,10 @@ class OptionsManagerMixIn:
self.set_current_module(config_file)
parser = self.cfgfile_parser
if config_file.endswith(".toml"):
- self._parse_toml(config_file, parser)
+ try:
+ self._parse_toml(config_file, parser)
+ except toml.TomlDecodeError as e:
+ self.add_message("config-parse-error", line=0, args=str(e))
else:
# Use this encoding in order to strip the BOM marker, if any.
with open(config_file, encoding="utf_8_sig") as fp:
diff --git a/pylint/lint/pylinter.py b/pylint/lint/pylinter.py
index 72ab3637c..913bc4a22 100644
--- a/pylint/lint/pylinter.py
+++ b/pylint/lint/pylinter.py
@@ -98,6 +98,11 @@ MSGS = {
"Used when an exception occurred while building the Astroid "
"representation which could be handled by astroid.",
),
+ "F0011": (
+ "error while parsing the configuration: %s",
+ "config-parse-error",
+ "Used when an exception occurred while parsing a pylint configuration file.",
+ ),
"I0001": (
"Unable to run raw checkers on built-in module %s",
"raw-checker-failed",
diff --git a/tests/config/functional/toml/issue_3181/toml_decode_error.1.out b/tests/config/functional/toml/issue_3181/toml_decode_error.1.out
new file mode 100644
index 000000000..ce4be6dad
--- /dev/null
+++ b/tests/config/functional/toml/issue_3181/toml_decode_error.1.out
@@ -0,0 +1,2 @@
+************* Module {abspath}
+{relpath}:1:0: F0010: error while code parsing: Found invalid character in key name: '*'. Try quoting the key name. (line 3 column 2 char 48) (parse-error)
diff --git a/tests/config/functional/toml/issue_3181/toml_decode_error.toml b/tests/config/functional/toml/issue_3181/toml_decode_error.toml
new file mode 100644
index 000000000..a59e46b3f
--- /dev/null
+++ b/tests/config/functional/toml/issue_3181/toml_decode_error.toml
@@ -0,0 +1,3 @@
+# TOML decode error crash pylint
+[tool.pylint]
+***
diff --git a/tests/config/functional/toml/issue_3181/top_level_list_of_disable.out b/tests/config/functional/toml/issue_3181/top_level_list_of_disable.out
new file mode 100644
index 000000000..b12d21046
--- /dev/null
+++ b/tests/config/functional/toml/issue_3181/top_level_list_of_disable.out
@@ -0,0 +1,3 @@
+************* Module {abspath}
+{relpath}:1:0: E0014: Out-of-place setting encountered in top level configuration-section 'max-line-length' : '120' (bad-configuration-section)
+{relpath}:1:0: E0014: Out-of-place setting encountered in top level configuration-section 'disable' : '['C0330']' (bad-configuration-section)
diff --git a/tests/config/functional/toml/issue_3181/top_level_list_of_disable.toml b/tests/config/functional/toml/issue_3181/top_level_list_of_disable.toml
new file mode 100644
index 000000000..ee43f8f9a
--- /dev/null
+++ b/tests/config/functional/toml/issue_3181/top_level_list_of_disable.toml
@@ -0,0 +1,4 @@
+# This crashed previously see https://github.com/PyCQA/pylint/issues/3181
+[tool.pylint]
+max-line-length = 120
+disable = ["C0330"]