Presubmit.Hunk (presubmit v0.2.2)

Copy Markdown View Source

A contiguous run of changed lines within one file, with zero context.

Line numbers on :del lines refer to the before-tree file; those on :add lines refer to the after-tree file, so an assertion can report path:line for the version of the file that will exist after the commit.

Summary

Functions

All added lines across hunks, in order.

Computes hunks between two texts using a line-level Myers diff.

All removed lines across hunks, in order.

Types

line()

@type line() :: {:add | :del, pos_integer(), String.t()}

t()

@type t() :: %Presubmit.Hunk{
  lines: [line()],
  new_count: non_neg_integer(),
  new_start: non_neg_integer(),
  old_count: non_neg_integer(),
  old_start: non_neg_integer()
}

Functions

added_lines(hunks)

@spec added_lines([t()]) :: [{pos_integer(), String.t()}]

All added lines across hunks, in order.

diff(before, after_text)

@spec diff(binary(), binary()) :: [t()]

Computes hunks between two texts using a line-level Myers diff.

Both inputs are split on \n; a trailing newline does not produce an empty final line.

removed_lines(hunks)

@spec removed_lines([t()]) :: [{pos_integer(), String.t()}]

All removed lines across hunks, in order.