Skip to content

Commit 0199504

Browse files
authored
Make sure that --generate-rcfile generates a valid file (#6566)
1 parent bc2fedc commit 0199504

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

pylint/utils/utils.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,11 @@ def _ini_format(stream: TextIO, options: list[tuple[str, OptionDict, Any]]) -> N
380380
DeprecationWarning,
381381
)
382382
for optname, optdict, value in options:
383+
# Skip deprecated option
384+
if "kwargs" in optdict:
385+
assert isinstance(optdict["kwargs"], dict)
386+
if "new_names" in optdict["kwargs"]:
387+
continue
383388
value = _format_option_value(optdict, value)
384389
help_opt = optdict.get("help")
385390
if help_opt:
@@ -389,7 +394,7 @@ def _ini_format(stream: TextIO, options: list[tuple[str, OptionDict, Any]]) -> N
389394
print(help_opt, file=stream)
390395
else:
391396
print(file=stream)
392-
if value is None:
397+
if value in {"None", "False"}:
393398
print(f"#{optname}=", file=stream)
394399
else:
395400
value = str(value).strip()

tests/test_self.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,6 +1345,17 @@ def test_generate_rcfile() -> None:
13451345
)
13461346
assert process.stdout == process_two.stdout
13471347

1348+
# Check that the generated file is valid
1349+
with tempfile.NamedTemporaryFile(mode="w", delete=False) as temp:
1350+
filename = temp.name
1351+
temp.write(process.stdout)
1352+
runner = Run(
1353+
[join(HERE, "regrtest_data", "empty.py"), f"--rcfile={filename}"],
1354+
exit=False,
1355+
)
1356+
assert not runner.linter.msg_status
1357+
os.remove(filename)
1358+
13481359
@staticmethod
13491360
def test_generate_config_disable_symbolic_names() -> None:
13501361
"""Test that --generate-rcfile puts symbolic names in the --disable option."""

0 commit comments

Comments
 (0)