Пример #1
0
 def get_full_documentation(self, msgs, options, reports, doc=None, module=None):
     result = ""
     checker_title = "%s checker" % (self.name.replace("_", " ").title())
     if module:
         # Provide anchor to link against
         result += ".. _%s:\n\n" % module
     result += "%s\n" % get_rst_title(checker_title, "~")
     if module:
         result += "This checker is provided by ``%s``.\n" % module
     result += "Verbatim name of the checker is ``%s``.\n\n" % self.name
     if doc:
         # Provide anchor to link against
         result += get_rst_title("{} Documentation".format(checker_title), "^")
         result += "%s\n\n" % cleandoc(doc)
     # options might be an empty generator and not be False when casted to boolean
     options = list(options)
     if options:
         result += get_rst_title("{} Options".format(checker_title), "^")
         result += "%s\n" % get_rst_section(None, options)
     if msgs:
         result += get_rst_title("{} Messages".format(checker_title), "^")
         for msgid, msg in sorted(
             msgs.items(), key=lambda kv: (_MSG_ORDER.index(kv[0][0]), kv[1])
         ):
             msg = self.create_message_definition_from_tuple(msgid, msg)
             result += "%s\n" % msg.format_help(checkerref=False)
         result += "\n"
     if reports:
         result += get_rst_title("{} Reports".format(checker_title), "^")
         for report in reports:
             result += ":%s: %s\n" % report[:2]
         result += "\n"
     result += "\n"
     return result
Пример #2
0
    def _print_checker_doc(checker_name, info, stream=None):
        """Helper method for print_full_documentation.

        Also used by doc/exts/pylint_extensions.py.
        """
        if not stream:
            stream = sys.stdout

        doc = info.get("doc")
        module = info.get("module")
        msgs = info.get("msgs")
        options = info.get("options")
        reports = info.get("reports")

        checker_title = "%s checker" % (checker_name.replace("_", " ").title())

        if module:
            # Provide anchor to link against
            print(".. _%s:\n" % module, file=stream)
        print(checker_title, file=stream)
        print("~" * len(checker_title), file=stream)
        print("", file=stream)
        if module:
            print("This checker is provided by ``%s``." % module, file=stream)
        print("Verbatim name of the checker is ``%s``." % checker_name,
              file=stream)
        print("", file=stream)
        if doc:
            # Provide anchor to link against
            title = "{} Documentation".format(checker_title)
            print(title, file=stream)
            print("^" * len(title), file=stream)
            print(cleandoc(doc), file=stream)
            print("", file=stream)
        if options:
            title = "{} Options".format(checker_title)
            print(title, file=stream)
            print("^" * len(title), file=stream)
            _rest_format_section(stream, None, options)
            print("", file=stream)
        if msgs:
            title = "{} Messages".format(checker_title)
            print(title, file=stream)
            print("^" * len(title), file=stream)
            for msgid, msg in sorted(msgs.items(),
                                     key=lambda kv:
                                     (_MSG_ORDER.index(kv[0][0]), kv[1])):
                msg = build_message_definition(checker_name, msgid, msg)
                print(msg.format_help(checkerref=False), file=stream)
            print("", file=stream)
        if reports:
            title = "{} Reports".format(checker_title)
            print(title, file=stream)
            print("^" * len(title), file=stream)
            for report in reports:
                print(":%s: %s" % report[:2], file=stream)
            print("", file=stream)
        print("", file=stream)
Пример #3
0
 def get_full_documentation(
     self,
     msgs: dict[str, MessageDefinitionTuple],
     options: Iterator[tuple[str, OptionDict, Any]],
     reports: tuple[tuple[str, str, ReportsCallable], ...],
     doc: str | None = None,
     module: str | None = None,
     show_options: bool = True,
 ) -> str:
     result = ""
     checker_title = f"{self.name.replace('_', ' ').title()} checker"
     if module:
         # Provide anchor to link against
         result += f".. _{module}:\n\n"
     result += f"{get_rst_title(checker_title, '~')}\n"
     if module:
         result += f"This checker is provided by ``{module}``.\n"
     result += f"Verbatim name of the checker is ``{self.name}``.\n\n"
     if doc:
         # Provide anchor to link against
         result += get_rst_title(f"{checker_title} Documentation", "^")
         result += f"{cleandoc(doc)}\n\n"
     # options might be an empty generator and not be False when cast to boolean
     options_list = list(options)
     if options_list:
         if show_options:
             result += get_rst_title(f"{checker_title} Options", "^")
             result += f"{get_rst_section(None, options_list)}\n"
         else:
             result += f"See also :ref:`{self.name} checker's options' documentation <{self.name}-options>`\n\n"
     if msgs:
         result += get_rst_title(f"{checker_title} Messages", "^")
         for msgid, msg in sorted(msgs.items(),
                                  key=lambda kv:
                                  (_MSG_ORDER.index(kv[0][0]), kv[1])):
             msg_def = self.create_message_definition_from_tuple(msgid, msg)
             result += f"{msg_def.format_help(checkerref=False)}\n"
         result += "\n"
     if reports:
         result += get_rst_title(f"{checker_title} Reports", "^")
         for report in reports:
             result += (
                 ":%s: %s\n" % report[:2]  # pylint: disable=consider-using-f-string
             )
         result += "\n"
     result += "\n"
     return result
Пример #4
0
 def get_full_documentation(self,
                            msgs,
                            options,
                            reports,
                            doc=None,
                            module=None):
     result = ""
     checker_title = f"{self.name.replace('_', ' ').title()} checker"
     if module:
         # Provide anchor to link against
         result += f".. _{module}:\n\n"
     result += f"{get_rst_title(checker_title, '~')}\n"
     if module:
         result += f"This checker is provided by ``{module}``.\n"
     result += f"Verbatim name of the checker is ``{self.name}``.\n\n"
     if doc:
         # Provide anchor to link against
         result += get_rst_title(f"{checker_title} Documentation", "^")
         result += f"{cleandoc(doc)}\n\n"
     # options might be an empty generator and not be False when casted to boolean
     options = list(options)
     if options:
         result += get_rst_title(f"{checker_title} Options", "^")
         result += f"{get_rst_section(None, options)}\n"
     if msgs:
         result += get_rst_title(f"{checker_title} Messages", "^")
         for msgid, msg in sorted(msgs.items(),
                                  key=lambda kv:
                                  (_MSG_ORDER.index(kv[0][0]), kv[1])):
             msg = self.create_message_definition_from_tuple(msgid, msg)
             result += f"{msg.format_help(checkerref=False)}\n"
         result += "\n"
     if reports:
         result += get_rst_title(f"{checker_title} Reports", "^")
         for report in reports:
             result += (
                 ":%s: %s\n" % report[:2]  # pylint: disable=consider-using-f-string
             )
         result += "\n"
     result += "\n"
     return result