Skip to content

Make sure that --generate-rcfile generates a valid file #6566

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion pylint/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,11 @@ def _ini_format(stream: TextIO, options: list[tuple[str, OptionDict, Any]]) -> N
DeprecationWarning,
)
for optname, optdict, value in options:
# Skip deprecated option
if "kwargs" in optdict:
assert isinstance(optdict["kwargs"], dict)
if "new_names" in optdict["kwargs"]:
continue
value = _format_option_value(optdict, value)
help_opt = optdict.get("help")
if help_opt:
Expand All @@ -389,7 +394,7 @@ def _ini_format(stream: TextIO, options: list[tuple[str, OptionDict, Any]]) -> N
print(help_opt, file=stream)
else:
print(file=stream)
if value is None:
if value in {"None", "False"}:
print(f"#{optname}=", file=stream)
else:
value = str(value).strip()
Expand Down
12 changes: 12 additions & 0 deletions tests/test_self.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import re
import subprocess
import sys
import tempfile
import textwrap
import warnings
from collections.abc import Generator, Iterator
Expand Down Expand Up @@ -1344,6 +1345,17 @@ def test_generate_rcfile() -> None:
)
assert process.stdout == process_two.stdout

# Check that the generated file is valid
with tempfile.NamedTemporaryFile(mode="w", delete=False) as temp:
filename = temp.name
temp.write(process.stdout)
runner = Run(
[join(HERE, "regrtest_data", "empty.py"), f"--rcfile={filename}"],
exit=False,
)
assert not runner.linter.msg_status
os.remove(filename)

@staticmethod
def test_generate_config_disable_symbolic_names() -> None:
"""Test that --generate-rcfile puts symbolic names in the --disable option."""
Expand Down