Skip to content

Commit bc2fedc

Browse files
authored
Make sure that --generate-toml-config generates a valid file (#6564)
1 parent 874cb43 commit bc2fedc

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

pylint/config/arguments_manager.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ def _generate_config_file(self) -> None:
665665
key=lambda x: (x.title != "Master", x.title),
666666
):
667667
# Skip the options section with the --help option
668-
if group.title == "options":
668+
if group.title in {"options", "optional arguments", "Commands"}:
669669
continue
670670

671671
# Skip sections without options such as "positional arguments"
@@ -703,6 +703,12 @@ def _generate_config_file(self) -> None:
703703
group_table.add(tomlkit.nl())
704704
continue
705705

706+
# Skip deprecated options
707+
if "kwargs" in optdict:
708+
assert isinstance(optdict["kwargs"], dict)
709+
if "new_names" in optdict["kwargs"]:
710+
continue
711+
706712
# Tomlkit doesn't support regular expressions
707713
if isinstance(value, re.Pattern):
708714
value = value.pattern
@@ -711,6 +717,10 @@ def _generate_config_file(self) -> None:
711717
):
712718
value = [i.pattern for i in value]
713719

720+
# Handle tuples that should be strings
721+
if optdict.get("type") == "py_version":
722+
value = ".".join(str(i) for i in value)
723+
714724
# Add to table
715725
group_table.add(optname, value)
716726
group_table.add(tomlkit.nl())

tests/test_self.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import re
1515
import subprocess
1616
import sys
17+
import tempfile
1718
import textwrap
1819
import warnings
1920
from collections.abc import Generator, Iterator
@@ -1384,6 +1385,7 @@ def test_generate_toml_config() -> None:
13841385
)
13851386
assert "[tool.pylint.master]" in process.stdout
13861387
assert '"positional arguments"' not in process.stdout
1388+
assert '"optional arguments"' not in process.stdout
13871389
assert 'preferred-modules = ["a:b"]' in process.stdout
13881390

13891391
process_two = subprocess.run(
@@ -1394,6 +1396,19 @@ def test_generate_toml_config() -> None:
13941396
)
13951397
assert process.stdout == process_two.stdout
13961398

1399+
# Check that the generated file is valid
1400+
with tempfile.NamedTemporaryFile(
1401+
mode="w", suffix=".toml", delete=False
1402+
) as temp:
1403+
filename = temp.name
1404+
temp.write(process.stdout)
1405+
runner = Run(
1406+
[join(HERE, "regrtest_data", "empty.py"), f"--rcfile={filename}"],
1407+
exit=False,
1408+
)
1409+
assert not runner.linter.msg_status
1410+
os.remove(filename)
1411+
13971412
@staticmethod
13981413
def test_generate_toml_config_disable_symbolic_names() -> None:
13991414
"""Test that --generate-toml-config puts symbolic names in the --disable option."""

0 commit comments

Comments
 (0)