Skip to content
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

Add output as JSON #158

Closed
wants to merge 5 commits into from
Closed

Add output as JSON #158

wants to merge 5 commits into from

Conversation

akrantz01
Copy link
Contributor

Resolves #73

This adds the ability to output the diff as JSON instead of text for both file and directory diffs. The individual token changes are all grouped by lines with left- and right-hand sides to preserve syntax awareness and make it clear which lines were changed.

Example outputs:

difft sample_files/json_before.json sample_files/json_after.json
{
  "language": "JSON",
  "path": "sample_files/json_after.json",
  "chunks": [
    [
      {
        "lhs": {
          "number": 2,
          "changes": [
            {
              "start": 2,
              "end": 7,
              "content": "\"bar\"",
              "kind": "keyword"
            }
          ]
        },
        "rhs": {
          "number": 2,
          "changes": [
            {
              "start": 2,
              "end": 7,
              "content": "\"zab\"",
              "kind": "keyword"
            },
            {
              "start": 18,
              "end": 19,
              "content": ",",
              "kind": "normal"
            }
          ]
        }
      },
      {
        "rhs": {
          "number": 3,
          "changes": [
            {
              "start": 2,
              "end": 7,
              "content": "\"woo\"",
              "kind": "keyword"
            },
            {
              "start": 7,
              "end": 8,
              "content": ":",
              "kind": "normal"
            },
            {
              "start": 9,
              "end": 10,
              "content": "[",
              "kind": "delimiter"
            },
            {
              "start": 10,
              "end": 18,
              "content": "\"foobar\"",
              "kind": "string"
            },
            {
              "start": 18,
              "end": 19,
              "content": "]",
              "kind": "delimiter"
            }
          ]
        }
      },
      {
        "lhs": {
          "number": 1,
          "changes": [
            {
              "start": 10,
              "end": 11,
              "content": "1",
              "kind": "normal"
            },
            {
              "start": 11,
              "end": 12,
              "content": ",",
              "kind": "normal"
            }
          ]
        },
        "rhs": {
          "number": 1,
          "changes": [
            {
              "start": 17,
              "end": 18,
              "content": ",",
              "kind": "normal"
            },
            {
              "start": 19,
              "end": 20,
              "content": "5",
              "kind": "normal"
            }
          ]
        }
      }
    ]
  ],
  "status": "changed"
}
difft sample_files/javascript_before.js sample_files/javascript_after.js
{
  "language": "JavaScript",
  "path": "sample_files/javascript_after.js",
  "chunks": [
    [
      {
        "lhs": {
          "number": 9,
          "changes": [
            {
              "start": 7,
              "end": 22,
              "content": "\"Editing pages\"",
              "kind": "string"
            }
          ]
        },
        "rhs": {
          "number": 9,
          "changes": [
            {
              "start": 7,
              "end": 18,
              "content": "\"/edit GET\"",
              "kind": "string"
            }
          ]
        }
      }
    ],
    [
      {
        "rhs": {
          "number": 24,
          "changes": [
            {
              "start": 8,
              "end": 9,
              "content": ".",
              "kind": "normal"
            },
            {
              "start": 9,
              "end": 13,
              "content": "type",
              "kind": "normal"
            },
            {
              "start": 13,
              "end": 14,
              "content": "(",
              "kind": "delimiter"
            },
            {
              "start": 14,
              "end": 20,
              "content": "\"form\"",
              "kind": "string"
            },
            {
              "start": 20,
              "end": 21,
              "content": ")",
              "kind": "delimiter"
            }
          ]
        }
      },
      {
        "rhs": {
          "number": 28,
          "changes": [
            {
              "start": 10,
              "end": 16,
              "content": "expect",
              "kind": "normal"
            },
            {
              "start": 16,
              "end": 17,
              "content": "(",
              "kind": "delimiter"
            },
            {
              "start": 17,
              "end": 20,
              "content": "res",
              "kind": "normal"
            },
            {
              "start": 20,
              "end": 21,
              "content": ".",
              "kind": "normal"
            },
            {
              "start": 21,
              "end": 28,
              "content": "headers",
              "kind": "normal"
            },
            {
              "start": 28,
              "end": 29,
              "content": "[",
              "kind": "delimiter"
            },
            {
              "start": 29,
              "end": 47,
              "content": "\"www-authenticate\"",
              "kind": "string"
            },
            {
              "start": 47,
              "end": 48,
              "content": "]",
              "kind": "delimiter"
            },
            {
              "start": 48,
              "end": 49,
              "content": ")",
              "kind": "delimiter"
            },
            {
              "start": 49,
              "end": 50,
              "content": ".",
              "kind": "normal"
            },
            {
              "start": 50,
              "end": 54,
              "content": "toBe",
              "kind": "normal"
            },
            {
              "start": 54,
              "end": 55,
              "content": "(",
              "kind": "delimiter"
            },
            {
              "start": 55,
              "end": 62,
              "content": "\"Basic\"",
              "kind": "string"
            },
            {
              "start": 62,
              "end": 63,
              "content": ")",
              "kind": "delimiter"
            },
            {
              "start": 63,
              "end": 64,
              "content": ";",
              "kind": "normal"
            }
          ]
        }
      },
      {
        "rhs": {
          "number": 30,
          "changes": [
            {
              "start": 8,
              "end": 9,
              "content": "}",
              "kind": "delimiter"
            },
            {
              "start": 9,
              "end": 10,
              "content": ")",
              "kind": "delimiter"
            },
            {
              "start": 10,
              "end": 11,
              "content": ";",
              "kind": "normal"
            }
          ]
        }
      },
      {
        "lhs": {
          "number": 19,
          "changes": [
            {
              "start": 7,
              "end": 23,
              "content": "\"Creating pages\"",
              "kind": "string"
            }
          ]
        },
        "rhs": {
          "number": 34,
          "changes": [
            {
              "start": 7,
              "end": 17,
              "content": "\"/new GET\"",
              "kind": "string"
            }
          ]
        }
      },
      {
        "rhs": {
          "number": 31,
          "changes": [
            {
              "start": 4,
              "end": 5,
              "content": "}",
              "kind": "delimiter"
            },
            {
              "start": 5,
              "end": 6,
              "content": ")",
              "kind": "delimiter"
            },
            {
              "start": 6,
              "end": 7,
              "content": ";",
              "kind": "normal"
            }
          ]
        }
      },
      {
        "rhs": {
          "number": 23,
          "changes": [
            {
              "start": 8,
              "end": 9,
              "content": ".",
              "kind": "normal"
            },
            {
              "start": 9,
              "end": 13,
              "content": "post",
              "kind": "normal"
            },
            {
              "start": 13,
              "end": 14,
              "content": "(",
              "kind": "delimiter"
            },
            {
              "start": 14,
              "end": 22,
              "content": "\"/edit/\"",
              "kind": "string"
            },
            {
              "start": 23,
              "end": 24,
              "content": "+",
              "kind": "keyword"
            },
            {
              "start": 25,
              "end": 29,
              "content": "page",
              "kind": "normal"
            },
            {
              "start": 29,
              "end": 30,
              "content": ".",
              "kind": "normal"
            },
            {
              "start": 30,
              "end": 35,
              "content": "rowid",
              "kind": "normal"
            },
            {
              "start": 35,
              "end": 36,
              "content": ")",
              "kind": "delimiter"
            }
          ]
        }
      },
      {
        "rhs": {
          "number": 19,
          "changes": [
            {
              "start": 4,
              "end": 6,
              "content": "db",
              "kind": "normal"
            },
            {
              "start": 6,
              "end": 7,
              "content": ".",
              "kind": "normal"
            },
            {
              "start": 7,
              "end": 17,
              "content": "createPage",
              "kind": "normal"
            },
            {
              "start": 17,
              "end": 18,
              "content": "(",
              "kind": "delimiter"
            },
            {
              "start": 18,
              "end": 35,
              "content": "\"EditAuthExample\"",
              "kind": "string"
            },
            {
              "start": 35,
              "end": 36,
              "content": ",",
              "kind": "normal"
            },
            {
              "start": 37,
              "end": 46,
              "content": "\"foo bar\"",
              "kind": "string"
            },
            {
              "start": 46,
              "end": 47,
              "content": ",",
              "kind": "normal"
            },
            {
              "start": 48,
              "end": 49,
              "content": "(",
              "kind": "delimiter"
            },
            {
              "start": 49,
              "end": 52,
              "content": "err",
              "kind": "normal"
            },
            {
              "start": 52,
              "end": 53,
              "content": ",",
              "kind": "normal"
            },
            {
              "start": 54,
              "end": 58,
              "content": "page",
              "kind": "normal"
            },
            {
              "start": 58,
              "end": 59,
              "content": ")",
              "kind": "delimiter"
            },
            {
              "start": 60,
              "end": 62,
              "content": "=>",
              "kind": "keyword"
            },
            {
              "start": 63,
              "end": 64,
              "content": "{",
              "kind": "delimiter"
            }
          ]
        }
      },
      {
        "rhs": {
          "number": 29,
          "changes": [
            {
              "start": 10,
              "end": 14,
              "content": "done",
              "kind": "normal"
            },
            {
              "start": 14,
              "end": 15,
              "content": "(",
              "kind": "delimiter"
            },
            {
              "start": 15,
              "end": 16,
              "content": ")",
              "kind": "delimiter"
            },
            {
              "start": 16,
              "end": 17,
              "content": ";",
              "kind": "normal"
            }
          ]
        }
      },
      {
        "rhs": {
          "number": 22,
          "changes": [
            {
              "start": 6,
              "end": 13,
              "content": "request",
              "kind": "normal"
            },
            {
              "start": 13,
              "end": 14,
              "content": "(",
              "kind": "delimiter"
            },
            {
              "start": 14,
              "end": 17,
              "content": "app",
              "kind": "normal"
            },
            {
              "start": 17,
              "end": 18,
              "content": ")",
              "kind": "delimiter"
            }
          ]
        }
      },
      {
        "rhs": {
          "number": 20,
          "changes": [
            {
              "start": 6,
              "end": 12,
              "content": "expect",
              "kind": "normal"
            },
            {
              "start": 12,
              "end": 13,
              "content": "(",
              "kind": "delimiter"
            },
            {
              "start": 13,
              "end": 16,
              "content": "err",
              "kind": "normal"
            },
            {
              "start": 16,
              "end": 17,
              "content": ")",
              "kind": "delimiter"
            },
            {
              "start": 17,
              "end": 18,
              "content": ".",
              "kind": "normal"
            },
            {
              "start": 18,
              "end": 26,
              "content": "toBeNull",
              "kind": "normal"
            },
            {
              "start": 26,
              "end": 27,
              "content": "(",
              "kind": "delimiter"
            },
            {
              "start": 27,
              "end": 28,
              "content": ")",
              "kind": "delimiter"
            },
            {
              "start": 28,
              "end": 29,
              "content": ";",
              "kind": "normal"
            }
          ]
        }
      },
      {
        "rhs": {
          "number": 25,
          "changes": [
            {
              "start": 8,
              "end": 9,
              "content": ".",
              "kind": "normal"
            },
            {
              "start": 9,
              "end": 13,
              "content": "send",
              "kind": "normal"
            },
            {
              "start": 13,
              "end": 14,
              "content": "(",
              "kind": "delimiter"
            },
            {
              "start": 14,
              "end": 15,
              "content": "{",
              "kind": "delimiter"
            },
            {
              "start": 16,
              "end": 20,
              "content": "name",
              "kind": "normal"
            },
            {
              "start": 20,
              "end": 21,
              "content": ":",
              "kind": "normal"
            },
            {
              "start": 22,
              "end": 39,
              "content": "\"EditPostExample\"",
              "kind": "string"
            },
            {
              "start": 39,
              "end": 40,
              "content": ",",
              "kind": "normal"
            },
            {
              "start": 41,
              "end": 48,
              "content": "content",
              "kind": "normal"
            },
            {
              "start": 48,
              "end": 49,
              "content": ":",
              "kind": "normal"
            },
            {
              "start": 50,
              "end": 63,
              "content": "\"hello world\"",
              "kind": "string"
            },
            {
              "start": 64,
              "end": 65,
              "content": "}",
              "kind": "delimiter"
            },
            {
              "start": 65,
              "end": 66,
              "content": ")",
              "kind": "delimiter"
            }
          ]
        }
      },
      {
        "rhs": {
          "number": 26,
          "changes": [
            {
              "start": 8,
              "end": 9,
              "content": ".",
              "kind": "normal"
            },
            {
              "start": 9,
              "end": 13,
              "content": "then",
              "kind": "normal"
            },
            {
              "start": 13,
              "end": 14,
              "content": "(",
              "kind": "delimiter"
            },
            {
              "start": 14,
              "end": 17,
              "content": "res",
              "kind": "normal"
            },
            {
              "start": 18,
              "end": 20,
              "content": "=>",
              "kind": "keyword"
            },
            {
              "start": 21,
              "end": 22,
              "content": "{",
              "kind": "delimiter"
            }
          ]
        }
      },
      {
        "lhs": {
          "number": 18,
          "changes": []
        },
        "rhs": {
          "number": 18,
          "changes": [
            {
              "start": 2,
              "end": 6,
              "content": "test",
              "kind": "normal"
            },
            {
              "start": 6,
              "end": 7,
              "content": "(",
              "kind": "delimiter"
            },
            {
              "start": 7,
              "end": 19,
              "content": "\"/edit POST\"",
              "kind": "string"
            },
            {
              "start": 19,
              "end": 20,
              "content": ",",
              "kind": "normal"
            },
            {
              "start": 21,
              "end": 25,
              "content": "done",
              "kind": "normal"
            },
            {
              "start": 26,
              "end": 28,
              "content": "=>",
              "kind": "keyword"
            },
            {
              "start": 29,
              "end": 30,
              "content": "{",
              "kind": "delimiter"
            }
          ]
        }
      },
      {
        "rhs": {
          "number": 27,
          "changes": [
            {
              "start": 10,
              "end": 16,
              "content": "expect",
              "kind": "normal"
            },
            {
              "start": 16,
              "end": 17,
              "content": "(",
              "kind": "delimiter"
            },
            {
              "start": 17,
              "end": 20,
              "content": "res",
              "kind": "normal"
            },
            {
              "start": 20,
              "end": 21,
              "content": ".",
              "kind": "normal"
            },
            {
              "start": 21,
              "end": 31,
              "content": "statusCode",
              "kind": "normal"
            },
            {
              "start": 31,
              "end": 32,
              "content": ")",
              "kind": "delimiter"
            },
            {
              "start": 32,
              "end": 33,
              "content": ".",
              "kind": "normal"
            },
            {
              "start": 33,
              "end": 37,
              "content": "toBe",
              "kind": "normal"
            },
            {
              "start": 37,
              "end": 38,
              "content": "(",
              "kind": "delimiter"
            },
            {
              "start": 38,
              "end": 41,
              "content": "401",
              "kind": "normal"
            },
            {
              "start": 41,
              "end": 42,
              "content": ")",
              "kind": "delimiter"
            },
            {
              "start": 42,
              "end": 43,
              "content": ";",
              "kind": "normal"
            }
          ]
        }
      },
      {
        "rhs": {
          "number": 32,
          "changes": [
            {
              "start": 2,
              "end": 3,
              "content": "}",
              "kind": "delimiter"
            },
            {
              "start": 3,
              "end": 4,
              "content": ")",
              "kind": "delimiter"
            },
            {
              "start": 4,
              "end": 5,
              "content": ";",
              "kind": "normal"
            }
          ]
        }
      }
    ],
    [
      {
        "rhs": {
          "number": 44,
          "changes": [
            {
              "start": 4,
              "end": 11,
              "content": "request",
              "kind": "normal"
            },
            {
              "start": 11,
              "end": 12,
              "content": "(",
              "kind": "delimiter"
            },
            {
              "start": 12,
              "end": 15,
              "content": "app",
              "kind": "normal"
            },
            {
              "start": 15,
              "end": 16,
              "content": ")",
              "kind": "delimiter"
            }
          ]
        }
      },
      {
        "rhs": {
          "number": 45,
          "changes": [
            {
              "start": 6,
              "end": 7,
              "content": ".",
              "kind": "normal"
            },
            {
              "start": 7,
              "end": 11,
              "content": "post",
              "kind": "normal"
            },
            {
              "start": 11,
              "end": 12,
              "content": "(",
              "kind": "delimiter"
            },
            {
              "start": 12,
              "end": 18,
              "content": "\"/new\"",
              "kind": "string"
            },
            {
              "start": 18,
              "end": 19,
              "content": ")",
              "kind": "delimiter"
            }
          ]
        }
      },
      {
        "rhs": {
          "number": 48,
          "changes": [
            {
              "start": 6,
              "end": 7,
              "content": ".",
              "kind": "normal"
            },
            {
              "start": 7,
              "end": 13,
              "content": "expect",
              "kind": "normal"
            },
            {
              "start": 13,
              "end": 14,
              "content": "(",
              "kind": "delimiter"
            },
            {
              "start": 14,
              "end": 17,
              "content": "401",
              "kind": "normal"
            },
            {
              "start": 17,
              "end": 18,
              "content": ",",
              "kind": "normal"
            },
            {
              "start": 19,
              "end": 23,
              "content": "done",
              "kind": "normal"
            },
            {
              "start": 23,
              "end": 24,
              "content": ")",
              "kind": "delimiter"
            },
            {
              "start": 24,
              "end": 25,
              "content": ";",
              "kind": "normal"
            }
          ]
        }
      },
      {
        "rhs": {
          "number": 49,
          "changes": [
            {
              "start": 2,
              "end": 3,
              "content": "}",
              "kind": "delimiter"
            },
            {
              "start": 3,
              "end": 4,
              "content": ")",
              "kind": "delimiter"
            },
            {
              "start": 4,
              "end": 5,
              "content": ";",
              "kind": "normal"
            }
          ]
        }
      },
      {
        "rhs": {
          "number": 43,
          "changes": [
            {
              "start": 2,
              "end": 6,
              "content": "test",
              "kind": "normal"
            },
            {
              "start": 6,
              "end": 7,
              "content": "(",
              "kind": "delimiter"
            },
            {
              "start": 7,
              "end": 18,
              "content": "\"/new POST\"",
              "kind": "string"
            },
            {
              "start": 18,
              "end": 19,
              "content": ",",
              "kind": "normal"
            },
            {
              "start": 20,
              "end": 24,
              "content": "done",
              "kind": "normal"
            },
            {
              "start": 25,
              "end": 27,
              "content": "=>",
              "kind": "keyword"
            },
            {
              "start": 28,
              "end": 29,
              "content": "{",
              "kind": "delimiter"
            }
          ]
        }
      },
      {
        "rhs": {
          "number": 46,
          "changes": [
            {
              "start": 6,
              "end": 7,
              "content": ".",
              "kind": "normal"
            },
            {
              "start": 7,
              "end": 11,
              "content": "type",
              "kind": "normal"
            },
            {
              "start": 11,
              "end": 12,
              "content": "(",
              "kind": "delimiter"
            },
            {
              "start": 12,
              "end": 18,
              "content": "\"form\"",
              "kind": "string"
            },
            {
              "start": 18,
              "end": 19,
              "content": ")",
              "kind": "delimiter"
            }
          ]
        }
      },
      {
        "rhs": {
          "number": 47,
          "changes": [
            {
              "start": 6,
              "end": 7,
              "content": ".",
              "kind": "normal"
            },
            {
              "start": 7,
              "end": 11,
              "content": "send",
              "kind": "normal"
            },
            {
              "start": 11,
              "end": 12,
              "content": "(",
              "kind": "delimiter"
            },
            {
              "start": 12,
              "end": 13,
              "content": "{",
              "kind": "delimiter"
            },
            {
              "start": 14,
              "end": 18,
              "content": "name",
              "kind": "normal"
            },
            {
              "start": 18,
              "end": 19,
              "content": ":",
              "kind": "normal"
            },
            {
              "start": 20,
              "end": 31,
              "content": "\"FooBarBaz\"",
              "kind": "string"
            },
            {
              "start": 31,
              "end": 32,
              "content": ",",
              "kind": "normal"
            },
            {
              "start": 33,
              "end": 40,
              "content": "content",
              "kind": "normal"
            },
            {
              "start": 40,
              "end": 41,
              "content": ":",
              "kind": "normal"
            },
            {
              "start": 42,
              "end": 55,
              "content": "\"hello world\"",
              "kind": "string"
            },
            {
              "start": 56,
              "end": 57,
              "content": "}",
              "kind": "delimiter"
            },
            {
              "start": 57,
              "end": 58,
              "content": ")",
              "kind": "delimiter"
            }
          ]
        }
      }
    ],
    [
      {
        "lhs": {
          "number": 58,
          "changes": [
            {
              "start": 7,
              "end": 18,
              "content": "\"/edit GET\"",
              "kind": "string"
            }
          ]
        },
        "rhs": {
          "number": 80,
          "changes": [
            {
              "start": 7,
              "end": 19,
              "content": "\"/edit POST\"",
              "kind": "string"
            }
          ]
        }
      }
    ],
    [
      {
        "rhs": {
          "number": 101,
          "changes": [
            {
              "start": 2,
              "end": 6,
              "content": "test",
              "kind": "normal"
            },
            {
              "start": 6,
              "end": 7,
              "content": "(",
              "kind": "delimiter"
            },
            {
              "start": 7,
              "end": 23,
              "content": "\"/AnExamplePage\"",
              "kind": "string"
            },
            {
              "start": 23,
              "end": 24,
              "content": ",",
              "kind": "normal"
            },
            {
              "start": 25,
              "end": 29,
              "content": "done",
              "kind": "normal"
            },
            {
              "start": 30,
              "end": 32,
              "content": "=>",
              "kind": "keyword"
            },
            {
              "start": 33,
              "end": 34,
              "content": "{",
              "kind": "delimiter"
            }
          ]
        }
      },
      {
        "rhs": {
          "number": 104,
          "changes": [
            {
              "start": 8,
              "end": 9,
              "content": ".",
              "kind": "normal"
            },
            {
              "start": 9,
              "end": 12,
              "content": "get",
              "kind": "normal"
            },
            {
              "start": 12,
              "end": 13,
              "content": "(",
              "kind": "delimiter"
            },
            {
              "start": 13,
              "end": 29,
              "content": "\"/AnExamplePage\"",
              "kind": "string"
            },
            {
              "start": 29,
              "end": 30,
              "content": ")",
              "kind": "delimiter"
            }
          ]
        }
      },
      {
        "rhs": {
          "number": 107,
          "changes": [
            {
              "start": 2,
              "end": 3,
              "content": "}",
              "kind": "delimiter"
            },
            {
              "start": 3,
              "end": 4,
              "content": ")",
              "kind": "delimiter"
            },
            {
              "start": 4,
              "end": 5,
              "content": ";",
              "kind": "normal"
            }
          ]
        }
      },
      {
        "rhs": {
          "number": 102,
          "changes": [
            {
              "start": 4,
              "end": 6,
              "content": "db",
              "kind": "normal"
            },
            {
              "start": 6,
              "end": 7,
              "content": ".",
              "kind": "normal"
            },
            {
              "start": 7,
              "end": 17,
              "content": "createPage",
              "kind": "normal"
            },
            {
              "start": 17,
              "end": 18,
              "content": "(",
              "kind": "delimiter"
            },
            {
              "start": 18,
              "end": 33,
              "content": "\"AnExamplePage\"",
              "kind": "string"
            },
            {
              "start": 33,
              "end": 34,
              "content": ",",
              "kind": "normal"
            },
            {
              "start": 35,
              "end": 44,
              "content": "\"foo bar\"",
              "kind": "string"
            },
            {
              "start": 44,
              "end": 45,
              "content": ",",
              "kind": "normal"
            },
            {
              "start": 46,
              "end": 47,
              "content": "(",
              "kind": "delimiter"
            },
            {
              "start": 47,
              "end": 48,
              "content": ")",
              "kind": "delimiter"
            },
            {
              "start": 49,
              "end": 51,
              "content": "=>",
              "kind": "keyword"
            },
            {
              "start": 52,
              "end": 53,
              "content": "{",
              "kind": "delimiter"
            }
          ]
        }
      },
      {
        "rhs": {
          "number": 94,
          "changes": [
            {
              "start": 0,
              "end": 8,
              "content": "describe",
              "kind": "normal"
            },
            {
              "start": 8,
              "end": 9,
              "content": "(",
              "kind": "delimiter"
            },
            {
              "start": 9,
              "end": 18,
              "content": "\"Viewing\"",
              "kind": "string"
            },
            {
              "start": 18,
              "end": 19,
              "content": ",",
              "kind": "normal"
            },
            {
              "start": 20,
              "end": 21,
              "content": "(",
              "kind": "delimiter"
            },
            {
              "start": 21,
              "end": 22,
              "content": ")",
              "kind": "delimiter"
            },
            {
              "start": 23,
              "end": 25,
              "content": "=>",
              "kind": "keyword"
            },
            {
              "start": 26,
              "end": 27,
              "content": "{",
              "kind": "delimiter"
            }
          ]
        }
      },
      {
        "rhs": {
          "number": 106,
          "changes": [
            {
              "start": 4,
              "end": 5,
              "content": "}",
              "kind": "delimiter"
            },
            {
              "start": 5,
              "end": 6,
              "content": ")",
              "kind": "delimiter"
            },
            {
              "start": 6,
              "end": 7,
              "content": ";",
              "kind": "normal"
            }
          ]
        }
      },
      {
        "rhs": {
          "number": 103,
          "changes": [
            {
              "start": 6,
              "end": 13,
              "content": "request",
              "kind": "normal"
            },
            {
              "start": 13,
              "end": 14,
              "content": "(",
              "kind": "delimiter"
            },
            {
              "start": 14,
              "end": 17,
              "content": "app",
              "kind": "normal"
            },
            {
              "start": 17,
              "end": 18,
              "content": ")",
              "kind": "delimiter"
            }
          ]
        }
      },
      {
        "rhs": {
          "number": 108,
          "changes": [
            {
              "start": 0,
              "end": 1,
              "content": "}",
              "kind": "delimiter"
            },
            {
              "start": 1,
              "end": 2,
              "content": ")",
              "kind": "delimiter"
            },
            {
              "start": 2,
              "end": 3,
              "content": ";",
              "kind": "normal"
            }
          ]
        }
      },
      {
        "rhs": {
          "number": 105,
          "changes": [
            {
              "start": 8,
              "end": 9,
              "content": ".",
              "kind": "normal"
            },
            {
              "start": 9,
              "end": 15,
              "content": "expect",
              "kind": "normal"
            },
            {
              "start": 15,
              "end": 16,
              "content": "(",
              "kind": "delimiter"
            },
            {
              "start": 16,
              "end": 19,
              "content": "200",
              "kind": "normal"
            },
            {
              "start": 19,
              "end": 20,
              "content": ",",
              "kind": "normal"
            },
            {
              "start": 21,
              "end": 25,
              "content": "done",
              "kind": "normal"
            },
            {
              "start": 25,
              "end": 26,
              "content": ")",
              "kind": "delimiter"
            },
            {
              "start": 26,
              "end": 27,
              "content": ";",
              "kind": "normal"
            }
          ]
        }
      }
    ]
  ],
  "status": "changed"
}

@codecov
Copy link

codecov bot commented Mar 13, 2022

Codecov Report

Patch coverage: 2.38% and project coverage change: -12.55 ⚠️

Comparison is base (2934c08) 83.10% compared to head (56dd5b3) 70.55%.

❗ Current head 56dd5b3 differs from pull request most recent head 5557459. Consider uploading reports for the commit 5557459 to get more accurate results

Additional details and impacted files
@@             Coverage Diff             @@
##           master     #158       +/-   ##
===========================================
- Coverage   83.10%   70.55%   -12.55%     
===========================================
  Files          23       22        -1     
  Lines        9338     6776     -2562     
===========================================
- Hits         7760     4781     -2979     
- Misses       1578     1995      +417     
Impacted Files Coverage Ξ”
src/json.rs 0.00% <0.00%> (ΓΈ)
src/main.rs 14.70% <0.00%> (-61.15%) ⬇️
src/options.rs 48.01% <71.42%> (-40.15%) ⬇️

... and 34 files with indirect coverage changes

β˜” View full report in Codecov by Sentry.
πŸ“’ Do you have feedback about the report comment? Let us know in this issue.

@lvh
Copy link

lvh commented Apr 3, 2022

This is a really neat PR! Do you have an expected use case in mind? (I only just learned about Difftastic and am curious about ways it could end up directly in the browser.)

@oberblastmeister
Copy link

This would allow integration with delta as described in this issue

@withzombies
Copy link

I updated this PR by rebasing it on current master: https://github.com/withzombies/difftastic/tree/json

@xangelix
Copy link

anything missing from this PR?

@rawnly
Copy link

rawnly commented Mar 20, 2023

Up! @Wilfred is this PR dead?

@marcelarie
Copy link

@akrantz01 what is the status of this PR ? :)

@akrantz01
Copy link
Contributor Author

Honestly not super sure, the project I had planned to use this for never really got started, so I no longer really have a use for it. However, I'm more than happy to rebase it to main to get it pushed through.

I'm currently dealing with final exams for uni, but I'll be able to get to it after this weekend.

@marcelarie
Copy link

Cool, thanks for the update.

@Wilfred
Copy link
Owner

Wilfred commented Apr 20, 2023

Sorry for the delay on reviewing this.

I was initially concerned about exposing internal details of difftastic types, which change pretty often. I see this is defining separate types, which largely solves that.

This should probably be --display=json rather than a new CLI argument, kind should be highlight I think, and the number field looks unnecessary, but the general approach looks good :)

@akrantz01
Copy link
Contributor Author

No worries! I think my original intention for the number field was to specify the line number. If that makes sense to keep, I'll rename it to line_number so it's more descriptive.

@akrantz01
Copy link
Contributor Author

Just rebased to the latest master with the proposed changes

@akrantz01
Copy link
Contributor Author

@Wilfred any updates on getting this reviewed and merged?

@mds1
Copy link

mds1 commented Jul 18, 2023

Hey @akrantz01 @Wilfred just wanted to see if we can resolve conflicts and get this merged :)

@Wilfred
Copy link
Owner

Wilfred commented Aug 17, 2023

Merged in 11a96e5, thanks! :)

This is pretty much the same code, just rebased on master and squashed. I've made two small changes:

(1) This is a big increase in the exposed API to users, and I'm cautious about committing to this specific format. For now, I'm requiring DFT_UNSTABLE=yes as an environment variable so we can collect feedback and tweak the format as needed.

(2) When diffing directories, difftastic will print the result of each file as soon as it's finished. This PR collected all the results and only printed at the end, so I've restored that behaviour.

@Wilfred Wilfred closed this Aug 17, 2023
Wilfred pushed a commit that referenced this pull request Apr 29, 2024
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.

Feature: provide an output as json
9 participants