Skip to content

Commit b7866c5

Browse files
[doc all-options] Proper sorting using the checker's ordering function
1 parent 036dec6 commit b7866c5

File tree

2 files changed

+962
-958
lines changed

2 files changed

+962
-958
lines changed

doc/exts/pylint_options.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ def _get_all_options(linter: PyLinter) -> OptionsDataDict:
5858
"""Get all options registered to a linter and return the data."""
5959
all_options: OptionsDataDict = defaultdict(list)
6060
for checker in sorted(linter.get_checkers()):
61-
checker_name = checker.name
6261
for option_name, option_info in checker.options:
6362
changes_to_do = DYNAMICALLY_DEFINED_OPTIONS.get(option_name, {})
6463
if changes_to_do:
@@ -68,7 +67,7 @@ def _get_all_options(linter: PyLinter) -> OptionsDataDict:
6867
f"{new_value!r} (instead of {option_info[key_to_change]!r})"
6968
)
7069
option_info[key_to_change] = new_value
71-
all_options[checker_name].append(
70+
all_options[checker.name].append(
7271
OptionsData(
7372
option_name,
7473
option_info,
@@ -176,12 +175,17 @@ def _write_options_page(options: OptionsDataDict, linter: PyLinter) -> None:
176175
get_rst_title("Standard Checkers", "^"),
177176
]
178177
found_extensions = False
179-
180-
for checker, checker_options in sorted(options.items()):
178+
# We can't sort without using a key because if keys are checkers
179+
# then it's impossible to have a checker with the same name spanning
180+
# various class, and it would make pylint plugin code less readable
181+
# by forcing to use a single class / file
182+
for checker_name, checker_options in sorted(
183+
options.items(), key=lambda x: x[1][0].checker
184+
):
181185
if not found_extensions and checker_options[0].extension:
182186
sections.append(get_rst_title("Extensions", "^"))
183187
found_extensions = True
184-
sections.append(_create_checker_section(checker, checker_options, linter))
188+
sections.append(_create_checker_section(checker_name, checker_options, linter))
185189

186190
all_options_path = PYLINT_USERGUIDE_PATH / "configuration" / "all-options.rst"
187191
sections_string = "\n\n".join(sections)

0 commit comments

Comments
 (0)