ickc/pandoc-amsthm

View on GitHub
src/amsthm/__init__.py

Summary

Maintainability
D
3 days
Test Coverage

File __init__.py has 381 lines of code (exceeds 250 allowed). Consider refactoring.
Open

from __future__ import annotations

import re
from collections import defaultdict
from dataclasses import dataclass, field
Severity: Minor
Found in src/amsthm/__init__.py - About 5 hrs to fix

    Function amsthm has a Cognitive Complexity of 34 (exceeds 5 allowed). Consider refactoring.
    Open

    def amsthm(elem: Element, doc: Doc) -> None:
        """General amsthm transformation working for all document types.
    
        Essentially we replicate LaTeX amsthm behavior in this filter.
        """
    Severity: Minor
    Found in src/amsthm/__init__.py - About 5 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function resolve_ref has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
    Open

    def resolve_ref(elem: Element, doc: Doc) -> pf.Str | None:
        """Resolve references to theorem numbers.
    
        Consider this as post-process ref for general output formats.
        """
    Severity: Minor
    Found in src/amsthm/__init__.py - About 3 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function from_doc has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
    Open

        def from_doc(
            cls,
            doc: Doc,
        ) -> DocOptions:
            options: dict[
    Severity: Minor
    Found in src/amsthm/__init__.py - About 3 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function to_panflute_theorem_header has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
    Open

        def to_panflute_theorem_header(
            self,
            options: DocOptions,
            id: str | None,
            info: str | None,
    Severity: Minor
    Found in src/amsthm/__init__.py - About 3 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function amsthm_latex has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

    def amsthm_latex(elem: Element, doc: Doc) -> pf.RawBlock | None:
        """Transform amsthm defintion to LaTeX package specifications."""
        # check if it is a Div, and the class is an amsthm environment
        options: DocOptions = doc._amsthm
        if isinstance(elem, pf.Div):
    Severity: Minor
    Found in src/amsthm/__init__.py - About 1 hr to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Avoid deeply nested control flow statements.
    Open

                            if isinstance(value, list):
                                for v in value:
                                    theorem = NewTheorem(style, v, text=name_to_text.get(v, ""), shared_counter=key)
                                    theorems[theorem.class_name] = theorem
                            else:
    Severity: Major
    Found in src/amsthm/__init__.py - About 45 mins to fix

      Avoid too many return statements within this function.
      Open

          return None
      Severity: Major
      Found in src/amsthm/__init__.py - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

                            return pf.Str(options.identifiers[id])
        Severity: Major
        Found in src/amsthm/__init__.py - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

                              return pf.Str(f"({options.identifiers[id]})")
          Severity: Major
          Found in src/amsthm/__init__.py - About 30 mins to fix

            Function latex has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def latex(self) -> str:
                    res = [r"\newtheorem"]
                    if not self.numbered:
                        res.append(f"*{{{self.env_name}}}{{{self.text}}}")
                    elif self.shared_counter is None:
            Severity: Minor
            Found in src/amsthm/__init__.py - About 25 mins to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Function latex has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def latex(self) -> str:
                    cur_style: str = ""
                    res: list[str] = []
                    for theorem in self.theorems.values():
                        # proof is predefined in amsthm
            Severity: Minor
            Found in src/amsthm/__init__.py - About 25 mins to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            There are no issues that match your filters.

            Category
            Status