diff options
author | Daniël van Noord <13665637+DanielNoord@users.noreply.github.com> | 2021-10-07 00:06:31 +0200 |
---|---|---|
committer | Daniël van Noord <13665637+DanielNoord@users.noreply.github.com> | 2021-10-07 17:22:33 +0200 |
commit | c4ed76d3948afdb0176835c1fa6eb48f54bfd54f (patch) | |
tree | f65896a555e4f8e89b278c94863bdf30773cab55 /pylint/utils | |
parent | 05d3e6c6e41e0aec9cf24c101a9a01f1046f61f6 (diff) | |
download | pylint-git-c4ed76d3948afdb0176835c1fa6eb48f54bfd54f.tar.gz |
Move docs helper functions out of ``MessagesHandlerMixIn``
Diffstat (limited to 'pylint/utils')
-rw-r--r-- | pylint/utils/__init__.py | 2 | ||||
-rw-r--r-- | pylint/utils/docs.py | 77 |
2 files changed, 79 insertions, 0 deletions
diff --git a/pylint/utils/__init__.py b/pylint/utils/__init__.py index 73f2e0fa0..aed86387b 100644 --- a/pylint/utils/__init__.py +++ b/pylint/utils/__init__.py @@ -44,6 +44,7 @@ main pylint class """ from pylint.utils.ast_walker import ASTWalker +from pylint.utils.docs import print_full_documentation from pylint.utils.file_state import FileState from pylint.utils.linterstats import LinterStats, ModuleStats, merge_stats from pylint.utils.utils import ( @@ -87,4 +88,5 @@ __all__ = [ "merge_stats", "LinterStats", "ModuleStats", + "print_full_documentation", ] diff --git a/pylint/utils/docs.py b/pylint/utils/docs.py new file mode 100644 index 000000000..5b46a0bc1 --- /dev/null +++ b/pylint/utils/docs.py @@ -0,0 +1,77 @@ +# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html +# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE +"""Various helper functions to create the docs of a linter object""" + +import sys +from typing import TYPE_CHECKING, Dict, TextIO + +from pylint.constants import MAIN_CHECKER_NAME +from pylint.utils.utils import get_rst_section, get_rst_title + +if TYPE_CHECKING: + from pylint.lint.pylinter import PyLinter + + +def _get_checkers_infos(linter: "PyLinter") -> Dict[str, Dict]: + """Get info from a checker and handle KeyError""" + by_checker: Dict[str, Dict] = {} + for checker in linter.get_checkers(): + name = checker.name + if name != "master": + try: + by_checker[name]["checker"] = checker + by_checker[name]["options"] += checker.options_and_values() + by_checker[name]["msgs"].update(checker.msgs) + by_checker[name]["reports"] += checker.reports + except KeyError: + by_checker[name] = { + "checker": checker, + "options": list(checker.options_and_values()), + "msgs": dict(checker.msgs), + "reports": list(checker.reports), + } + return by_checker + + +def _get_checkers_documentation(linter: "PyLinter") -> str: + """Get documentation for individual checkers""" + result = get_rst_title("Pylint global options and switches", "-") + result += """ +Pylint provides global options and switches. + +""" + for checker in linter.get_checkers(): + name = checker.name + if name == MAIN_CHECKER_NAME: + if checker.options: + for section, options in checker.options_by_section(): + if section is None: + title = "General options" + else: + title = f"{section.capitalize()} options" + result += get_rst_title(title, "~") + result += f"{get_rst_section(None, options)}\n" + result += get_rst_title("Pylint checkers' options and switches", "-") + result += """\ + +Pylint checkers can provide three set of features: + +* options that control their execution, +* messages that they can raise, +* reports that they can generate. + +Below is a list of all checkers and their features. + +""" + by_checker = _get_checkers_infos(linter) + for checker in sorted(by_checker): + information = by_checker[checker] + checker = information["checker"] + del information["checker"] + result += checker.get_full_documentation(**information) + return result + + +def print_full_documentation(linter: "PyLinter", stream: TextIO = sys.stdout) -> None: + """Output a full documentation in ReST format""" + print(_get_checkers_documentation(linter)[:-1], file=stream) |