SEIAROTg/autobean-format

View on GitHub

Showing 12 of 12 total issues

File sorting.py has 276 lines of code (exceeds 250 allowed). Consider refactoring.
Open

"""Sorts entities in a less disruptive way.
 
## Problems
 
Sorting beancount entities may sound as simple as `sorted(entities)` but doing it properly isn't trivial.
Severity: Minor
Found in autobean_format/internal/sorting.py - About 2 hrs to fix

    Function _split_sorted_unsorted has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
    Open

    def _split_sorted_unsorted(
    entities: Sequence[_O],
    ) -> tuple[list[_O], list[_O]]:
    # (running max index, entity index) -> (prev running max index, prev entity index)
    p = dict[tuple[int, int], tuple[int, int]]()
    Severity: Minor
    Found in autobean_format/internal/sorting.py - About 2 hrs to fix

    Function format_posting has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

    def format_posting(posting: models.Posting, context: base.Context) -> Iterator[models.RawTokenModel]:
     
    children_it = iterating.BufferedIterator(posting.iter_children_formatted())
     
    for child, indented in children_it.take_until(lambda x: isinstance(x[0], models.Indent)):
    Severity: Minor
    Found in autobean_format/formatters/posting.py - About 1 hr to fix

    Function _merge_entries has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

    def _merge_entries(sorted: Sequence['_OrderedEntry'], unsorted: Sequence['_OrderedEntry']) -> Iterator[Sequence['_OrderedEntry']]:
    cursor_sorted, cursor_unsorted = 0, 0
    reversed_running_min_unsorted = _build_reversed_running_min(unsorted)
    while cursor_sorted < len(sorted) and cursor_unsorted < len(unsorted):
    prev_cursor_sorted = cursor_sorted
    Severity: Minor
    Found in autobean_format/internal/sorting.py - About 1 hr to fix

    Function merge has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

    def merge(cls, sorted: list['_OrderedBlock'], unsorted: list['_OrderedBlock']) -> Iterator['_OrderedBlock']:
    keyed_unsorted = [(block.simple_sort_key(), block) for block in unsorted]
    heapq.heapify(keyed_unsorted)
    cursor_sorted = 0
    while cursor_sorted < len(sorted) and keyed_unsorted:
    Severity: Minor
    Found in autobean_format/internal/sorting.py - About 1 hr to fix

    Function format has 6 arguments (exceeds 4 allowed). Consider refactoring.
    Open

    def format(
    Severity: Minor
    Found in autobean_format/formatter.py - About 45 mins to fix

      Avoid too many return statements within this function.
      Open

      return None
      Severity: Major
      Found in autobean_format/internal/chrono.py - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

        return False
        Severity: Major
        Found in autobean_format/formatters/file.py - About 30 mins to fix

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

          def sort_blocks(blocks: Iterable[Sequence[_TopLevelEntitiy]]) -> list[Sequence[_TopLevelEntitiy]]:
          results = []
          compartment = list[_OrderedBlock]()
          first_entry_index = 0
          for block in blocks:
          Severity: Minor
          Found in autobean_format/internal/sorting.py - About 25 mins to fix

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

          def format_cost(cost: models.UnitCost | models.TotalCost, context: base.Context) -> Iterator[models.RawTokenModel]:
          spaces_in_braces = context.options.spaces_in_braces and next(iter(cost.raw_components), None) is not None
           
          for child, indented in cost.iter_children_formatted():
          if spaces_in_braces and isinstance(child, models.RightBrace | models.DblRightBrace):
          Severity: Minor
          Found in autobean_format/formatters/cost.py - About 25 mins to fix

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

          def _partition(file: models.File, context: base.Context) -> list[_Block]:
          prev = None
          last_block = None
          blocks: list[_Block] = []
          for child, indented in file.iter_children_formatted():
          Severity: Minor
          Found in autobean_format/formatters/file.py - About 25 mins to fix

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

          def format(model: models.RawModel, context: Context) -> Iterator[models.RawTokenModel]:
          formatter = _FORMATTERS.get(type(model))
          if formatter:
          yield from formatter(model, context)
          elif isinstance(model, models.RawTokenModel):
          Severity: Minor
          Found in autobean_format/formatters/base.py - About 25 mins to fix
          Severity
          Category
          Status
          Source
          Language