Skip to content

Commit 8b31ac7

Browse files
committed
Remove redundant options documentation and improve formatting
1 parent 8d59af6 commit 8b31ac7

File tree

5 files changed

+39
-27
lines changed

5 files changed

+39
-27
lines changed

doc/exts/pylint_extensions.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,10 @@ def builder_inited(app: Optional[Sphinx]) -> None:
7070
for checker, information in sorted(by_checker.items()):
7171
checker = information["checker"]
7272
del information["checker"]
73-
print(checker.get_full_documentation(**information)[:-1], file=stream)
73+
print(
74+
checker.get_full_documentation(**information, show_options=False)[:-1],
75+
file=stream,
76+
)
7477

7578

7679
def get_plugins_info(linter, doc_files):

doc/exts/pylint_features.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def builder_inited(app: Optional[Sphinx]) -> None:
3131
stream.write("Pylint features\n")
3232
stream.write("===============\n\n")
3333
stream.write(".. generated by pylint --full-documentation\n\n")
34-
print_full_documentation(linter, stream)
34+
print_full_documentation(linter, stream, False)
3535

3636

3737
def setup(app):

doc/exts/pylint_options.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def _get_all_options(linter: PyLinter) -> OptionsDataDict:
6666
def _create_checker_section(
6767
checker: str, options: list[OptionsData], linter: PyLinter
6868
) -> str:
69-
checker_string = get_rst_title(f"``{checker.capitalize()}`` Checker", "^")
69+
checker_string = get_rst_title(f"``{checker.capitalize()}`` **Checker**", "-")
7070

7171
toml_doc = tomlkit.document()
7272
pylint_tool_table = tomlkit.table(is_super_table=True)
@@ -76,11 +76,11 @@ def _create_checker_section(
7676

7777
for option in sorted(options, key=lambda x: x.name):
7878
checker_string += get_rst_title(f"--{option.name}", '"')
79-
checker_string += f"\nDescription:\n *{option.optdict.get('help')}*\n\n"
79+
checker_string += f"*{option.optdict.get('help')}*\n\n"
8080
if option.optdict.get("default") == "":
81-
checker_string += 'Default:\n ``""``\n\n\n'
81+
checker_string += '**Default:** ``""``\n\n\n'
8282
else:
83-
checker_string += f"Default:\n ``{option.optdict.get('default')}``\n\n\n"
83+
checker_string += f"**Default:** ``{option.optdict.get('default')}``\n\n\n"
8484

8585
# Start adding the option to the toml example
8686
if option.optdict.get("hide_from_config_file"):

pylint/checkers/base_checker.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ def get_full_documentation(
109109
reports: tuple[tuple[str, str, ReportsCallable], ...],
110110
doc: str | None = None,
111111
module: str | None = None,
112+
show_options: bool = True,
112113
) -> str:
113114
result = ""
114115
checker_title = f"{self.name.replace('_', ' ').title()} checker"
@@ -125,7 +126,7 @@ def get_full_documentation(
125126
result += f"{cleandoc(doc)}\n\n"
126127
# options might be an empty generator and not be False when cast to boolean
127128
options_list = list(options)
128-
if options_list:
129+
if options_list and show_options:
129130
result += get_rst_title(f"{checker_title} Options", "^")
130131
result += f"{get_rst_section(None, options_list)}\n"
131132
if msgs:

pylint/utils/docs.py

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -42,27 +42,29 @@ def _get_checkers_infos(linter: PyLinter) -> dict[str, dict[str, Any]]:
4242
return by_checker
4343

4444

45-
def _get_checkers_documentation(linter: PyLinter) -> str:
45+
def _get_checkers_documentation(linter: PyLinter, show_options: bool = True) -> str:
4646
"""Get documentation for individual checkers."""
47-
result = get_rst_title("Pylint global options and switches", "-")
48-
result += """
47+
result = ""
48+
if show_options:
49+
result += get_rst_title("Pylint global options and switches", "-")
50+
result += """
4951
Pylint provides global options and switches.
5052
5153
"""
52-
for checker in linter.get_checkers():
53-
name = checker.name
54-
if name == MAIN_CHECKER_NAME:
55-
if checker.options:
56-
with warnings.catch_warnings():
57-
warnings.filterwarnings("ignore", category=DeprecationWarning)
58-
for section, options in checker.options_by_section():
59-
if section is None:
60-
title = "General options"
61-
else:
62-
title = f"{section.capitalize()} options"
63-
result += get_rst_title(title, "~")
64-
assert isinstance(options, list)
65-
result += f"{get_rst_section(None, options)}\n"
54+
for checker in linter.get_checkers():
55+
name = checker.name
56+
if name == MAIN_CHECKER_NAME:
57+
if checker.options:
58+
with warnings.catch_warnings():
59+
warnings.filterwarnings("ignore", category=DeprecationWarning)
60+
for section, options in checker.options_by_section():
61+
if section is None:
62+
title = "General options"
63+
else:
64+
title = f"{section.capitalize()} options"
65+
result += get_rst_title(title, "~")
66+
assert isinstance(options, list)
67+
result += f"{get_rst_section(None, options)}\n"
6668
result += get_rst_title("Pylint checkers' options and switches", "-")
6769
result += """\
6870
@@ -80,10 +82,16 @@ def _get_checkers_documentation(linter: PyLinter) -> str:
8082
information = by_checker[checker_name]
8183
checker = information["checker"]
8284
del information["checker"]
83-
result += checker.get_full_documentation(**information)
85+
result += checker.get_full_documentation(
86+
**information, show_options=show_options
87+
)
8488
return result
8589

8690

87-
def print_full_documentation(linter: PyLinter, stream: TextIO = sys.stdout) -> None:
91+
def print_full_documentation(
92+
linter: PyLinter, stream: TextIO = sys.stdout, show_options: bool = True
93+
) -> None:
8894
"""Output a full documentation in ReST format."""
89-
print(_get_checkers_documentation(linter)[:-1], file=stream)
95+
print(
96+
_get_checkers_documentation(linter, show_options=show_options)[:-1], file=stream
97+
)

0 commit comments

Comments
 (0)