Skip to content

Commit ed8f2ac

Browse files
[config] Make the linter optional during config parsing
This will permit to parse config file without having to instantiate a linter for tool working on pylint configuration like #5462
1 parent 503d360 commit ed8f2ac

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

pylint/config/config_file_parser.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
class _ConfigurationFileParser:
2727
"""Class to parse various formats of configuration files."""
2828

29-
def __init__(self, verbose: bool, linter: PyLinter) -> None:
29+
def __init__(self, verbose: bool, linter: PyLinter | None = None) -> None:
3030
self.verbose_mode = verbose
3131
self.linter = linter
3232

@@ -64,7 +64,8 @@ def _parse_toml_file(self, file_path: Path) -> tuple[dict[str, str], list[str]]:
6464
with open(file_path, mode="rb") as fp:
6565
content = tomllib.load(fp)
6666
except tomllib.TOMLDecodeError as e:
67-
self.linter.add_message("config-parse-error", line=0, args=str(e))
67+
if self.linter is not None:
68+
self.linter.add_message("config-parse-error", line=0, args=str(e))
6869
return {}, []
6970

7071
try:
@@ -109,5 +110,6 @@ def parse_config_file(
109110
return self._parse_toml_file(file_path)
110111
return self._parse_ini_file(file_path)
111112
except (configparser.Error, tomllib.TOMLDecodeError) as e:
112-
self.linter.add_message("config-parse-error", line=0, args=str(e))
113+
if self.linter is not None:
114+
self.linter.add_message("config-parse-error", line=0, args=str(e))
113115
return {}, []

0 commit comments

Comments
 (0)