Skip to content

feat: support extending JSONFormatter #414

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

atsjo
Copy link

@atsjo atsjo commented Mar 29, 2025

Support extending JSONFormatter with custom text diff operations, and fix a potential bug where MovedDelta is identified as a TextDiffDelta:

  if (itemDelta[2] === 3) {
    throw new Error(
      "JSONPatch (RFC 6902) doesn't support text diffs, disable textDiff option",
    );
  }

As of now I have to make my own copy of JSONFormatter to extend it. By accepting this PR this would be a cleaner integration for me, and give other the same easy way of supporting custom text diffing operations by extending JSONFormatter like this:

class MyJSONFormatter extends JSONFormater {
  protected override processTextDiff(ops: Op[], path: string, diff: string) {
    const lines = parseTextDiff(diff);
    for (const line of lines) ...
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant