Skip to content
Permalink
Browse files

Add a --json-version flag for a more succinct JSON output with suppor…

…t for markup

Summary:
For Flow error message JSON consumers we can provide a new JSON format that allows consumers to take advantage of the rich markup format Flow now produces.

My proposed solution for providing this information to JSON consumers is to introduce a `--json-version=2` flag. `--json-version=2` implies `--json` like `--pretty` implies `--json`. Using the `--json` or `--pretty` flags without `--json-version=2` will give you the old JSON format. (`--json-version=1` will also give you the old format.) This means we don't break current Flow JSON consumers. (Considering some Flow JSON consumers don't yet support the `extra` field, it seems pretty important that the JSON format stay backwards compatible.)

Another possible solution would be to add new fields to the current JSON format while preserving the current fields. This would mean we don't need a `--json-version=2` flag. But this would increase the weight of Flow's JSON output for both updated JSON consumers and JSON consumers who depend on the legacy JSON format.

The new JSON format, in Flow types:

```
type Error = {
  kind: 'parse' | 'infer' | 'internal' | 'duplicate provider' | 'recursion limit exceeded' | 'lint',
  level: 'error' | 'warning',
  suppressions: Array<{ loc: Loc }>,
  // NOTE: `primaryLoc` is the location we want to show in an IDE! `rootLoc`
  // is another loc which Flow associates with some errors. We include it
  // for tools which are interested in using the location to enhance
  // their rendering. `primaryLoc` will always be inside `rootLoc`.
  primaryLoc: Loc,
  rootLoc: Loc | null,
  // NOTE: This `messageMarkup` can be concatenated into a string when
  // implementing the LSP error output.
  messageMarkup: Message,
  // NOTE: These `referenceLocs` can become `relatedLocations` when
  // implementing the LSP error output.
  referenceLocs: { [id: string]: Loc },
};

type Message = MessageInline | MessageBlock;

type MessageInline = Array<MessageInlineWithoutReference | MessageReference>;

type MessageInlineWithoutReference =
  | { kind: 'Text', text: string }
  | { kind: 'Code', text: string };

type MessageReference = {
  kind: 'Reference',
  referenceId: string,
  message: Array<MessageInlineWithoutReference>,
};

type MessageBlock = MessageUnorderedList;

type MessageUnorderedList = {
  kind: 'UnorderedList',
  message: MessageInline,
  items: Array<Message>,
};

type Loc = {
  source: string | null,
  type: 'LibFile' | 'SourceFile' | 'JsonFile' | 'ResourceFile' | 'Builtins' | null,
  start: Pos,
  end: Pos,
  context: string | null,
};

type Pos = {
  line: number,
  column: number,
  offset: number,
};
```

Reviewed By: gabelevi

Differential Revision: D6840940

fbshipit-source-id: a34a93ec727004d8e589872abb62efbf3acdb08f
  • Loading branch information...
calebmer authored and facebook-github-bot committed Feb 16, 2018
1 parent f8c2ae4 commit 28c8a3e5acd7ca9f17547ca38e54efd8475f9eb3
@@ -20,6 +20,7 @@ export default suite(({
"params": [
{
"flowVersion": "<VERSION STUBBED FOR TEST>",
"jsonVersion": "1",
"errors": [],
"passed": true
}
@@ -45,6 +46,7 @@ export default suite(({
"params": [
{
"flowVersion": "<VERSION STUBBED FOR TEST>",
"jsonVersion": "1",
"errors": [],
"passed": true
}
@@ -63,6 +65,7 @@ export default suite(({
"params": [
{
"flowVersion": "<VERSION STUBBED FOR TEST>",
"jsonVersion": "1",
"errors": [],
"passed": true
}
@@ -86,6 +89,7 @@ export default suite(({
"params": [
{
"flowVersion": "<VERSION STUBBED FOR TEST>",
"jsonVersion": "1",
"errors": [
{
"kind": "infer",
@@ -204,6 +208,7 @@ export default suite(({
"params": [
{
"flowVersion": "<VERSION STUBBED FOR TEST>",
"jsonVersion": "1",
"errors": [
{
"kind": "infer",
@@ -326,6 +331,7 @@ export default suite(({
"params": [
{
"flowVersion": "<VERSION STUBBED FOR TEST>",
"jsonVersion": "1",
"errors": [
{
"kind": "infer",
@@ -491,6 +497,7 @@ export default suite(({
"params": [
{
"flowVersion": "<VERSION STUBBED FOR TEST>",
"jsonVersion": "1",
"errors": [],
"passed": true
}
@@ -515,6 +522,7 @@ export default suite(({
"params": [
{
"flowVersion": "<VERSION STUBBED FOR TEST>",
"jsonVersion": "1",
"errors": [],
"passed": true
}
@@ -533,6 +541,7 @@ export default suite(({
"params": [
{
"flowVersion": "<VERSION STUBBED FOR TEST>",
"jsonVersion": "1",
"errors": [],
"passed": true
}
@@ -554,6 +563,7 @@ export default suite(({
"params": [
{
"flowVersion": "<VERSION STUBBED FOR TEST>",
"jsonVersion": "1",
"errors": [
{
"kind": "infer",
@@ -668,6 +678,7 @@ export default suite(({
"params": [
{
"flowVersion": "<VERSION STUBBED FOR TEST>",
"jsonVersion": "1",
"errors": [
{
"kind": "infer",
@@ -786,6 +797,7 @@ export default suite(({
"params": [
{
"flowVersion": "<VERSION STUBBED FOR TEST>",
"jsonVersion": "1",
"errors": [
{
"kind": "infer",
@@ -1072,6 +1084,7 @@ export default suite(({
"params": [
{
"flowVersion": "<VERSION STUBBED FOR TEST>",
"jsonVersion": "1",
"errors": [],
"passed": true
}
@@ -1090,6 +1103,7 @@ export default suite(({
"params": [
{
"flowVersion": "<VERSION STUBBED FOR TEST>",
"jsonVersion": "1",
"errors": [],
"passed": true
}
@@ -1110,6 +1124,7 @@ export default suite(({
"params": [
{
"flowVersion": "<VERSION STUBBED FOR TEST>",
"jsonVersion": "1",
"errors": [
{
"kind": "infer",
@@ -1228,6 +1243,7 @@ export default suite(({
"params": [
{
"flowVersion": "<VERSION STUBBED FOR TEST>",
"jsonVersion": "1",
"errors": [
{
"kind": "infer",
@@ -1346,6 +1362,7 @@ export default suite(({
"params": [
{
"flowVersion": "<VERSION STUBBED FOR TEST>",
"jsonVersion": "1",
"errors": [
{
"kind": "infer",
@@ -1464,6 +1481,7 @@ export default suite(({
"params": [
{
"flowVersion": "<VERSION STUBBED FOR TEST>",
"jsonVersion": "1",
"errors": [
{
"kind": "infer",
@@ -1606,6 +1624,7 @@ export default suite(({
"params": [
{
"flowVersion": "<VERSION STUBBED FOR TEST>",
"jsonVersion": "1",
"errors": [],
"passed": true
}
@@ -1624,6 +1643,7 @@ export default suite(({
"params": [
{
"flowVersion": "<VERSION STUBBED FOR TEST>",
"jsonVersion": "1",
"errors": [],
"passed": true
}
@@ -1666,6 +1686,7 @@ export default suite(({
"params": [
{
"flowVersion": "<VERSION STUBBED FOR TEST>",
"jsonVersion": "1",
"errors": [],
"passed": true
}
@@ -1690,6 +1711,7 @@ export default suite(({
"params": [
{
"flowVersion": "<VERSION STUBBED FOR TEST>",
"jsonVersion": "1",
"errors": [],
"passed": true
}
@@ -1708,6 +1730,7 @@ export default suite(({
"params": [
{
"flowVersion": "<VERSION STUBBED FOR TEST>",
"jsonVersion": "1",
"errors": [],
"passed": true
}
@@ -1728,6 +1751,7 @@ export default suite(({
"params": [
{
"flowVersion": "<VERSION STUBBED FOR TEST>",
"jsonVersion": "1",
"errors": [
{
"kind": "infer",
@@ -1846,6 +1870,7 @@ export default suite(({
"params": [
{
"flowVersion": "<VERSION STUBBED FOR TEST>",
"jsonVersion": "1",
"errors": [
{
"kind": "infer",
@@ -1994,6 +2019,7 @@ export default suite(({
"params": [
{
"flowVersion": "<VERSION STUBBED FOR TEST>",
"jsonVersion": "1",
"errors": [],
"passed": true
}
@@ -2075,6 +2101,7 @@ export default suite(({
"params": [
{
"flowVersion": "<VERSION STUBBED FOR TEST>",
"jsonVersion": "1",
"errors": [],
"passed": true
}
@@ -2093,6 +2120,7 @@ export default suite(({
"params": [
{
"flowVersion": "<VERSION STUBBED FOR TEST>",
"jsonVersion": "1",
"errors": [],
"passed": true
}
@@ -2227,6 +2255,7 @@ export default suite(({
"params": [
{
"flowVersion": "<VERSION STUBBED FOR TEST>",
"jsonVersion": "1",
"errors": [],
"passed": true
}
@@ -2245,6 +2274,7 @@ export default suite(({
"params": [
{
"flowVersion": "<VERSION STUBBED FOR TEST>",
"jsonVersion": "1",
"errors": [],
"passed": true
}
@@ -2347,6 +2377,7 @@ export default suite(({
"params": [
{
"flowVersion": "<VERSION STUBBED FOR TEST>",
"jsonVersion": "1",
"errors": [],
"passed": true
}
@@ -2365,6 +2396,7 @@ export default suite(({
"params": [
{
"flowVersion": "<VERSION STUBBED FOR TEST>",
"jsonVersion": "1",
"errors": [],
"passed": true
}
@@ -2466,6 +2498,7 @@ export default suite(({
"params": [
{
"flowVersion": "<VERSION STUBBED FOR TEST>",
"jsonVersion": "1",
"errors": [],
"passed": true
}
@@ -2484,6 +2517,7 @@ export default suite(({
"params": [
{
"flowVersion": "<VERSION STUBBED FOR TEST>",
"jsonVersion": "1",
"errors": [],
"passed": true
}
@@ -33,6 +33,7 @@ export default suite(({ideStart, ideNotification, ideRequest, addCode, addFile})
"params": [
{
"flowVersion": "<VERSION STUBBED FOR TEST>",
"jsonVersion": "1",
"errors": [
{
"kind": "infer",
@@ -159,6 +160,7 @@ export default suite(({ideStart, ideNotification, ideRequest, addCode, addFile})
"params": [
{
"flowVersion": "<VERSION STUBBED FOR TEST>",
"jsonVersion": "1",
"errors": [
{
"kind": "infer",
@@ -299,6 +301,7 @@ export default suite(({ideStart, ideNotification, ideRequest, addCode, addFile})
"params": [
{
"flowVersion": "<VERSION STUBBED FOR TEST>",
"jsonVersion": "1",
"errors": [
{
"kind": "infer",
@@ -421,6 +424,7 @@ export default suite(({ideStart, ideNotification, ideRequest, addCode, addFile})
"params": [
{
"flowVersion": "<VERSION STUBBED FOR TEST>",
"jsonVersion": "1",
"errors": [
{
"kind": "infer",
@@ -546,6 +550,7 @@ export default suite(({ideStart, ideNotification, ideRequest, addCode, addFile})
"params": [
{
"flowVersion": "<VERSION STUBBED FOR TEST>",
"jsonVersion": "1",
"errors": [
{
"kind": "infer",
@@ -664,6 +669,7 @@ export default suite(({ideStart, ideNotification, ideRequest, addCode, addFile})
"params": [
{
"flowVersion": "<VERSION STUBBED FOR TEST>",
"jsonVersion": "1",
"errors": [
{
"kind": "infer",
@@ -889,6 +895,7 @@ export default suite(({ideStart, ideNotification, ideRequest, addCode, addFile})
"params": [
{
"flowVersion": "<VERSION STUBBED FOR TEST>",
"jsonVersion": "1",
"errors": [
{
"kind": "infer",
@@ -1151,6 +1158,7 @@ export default suite(({ideStart, ideNotification, ideRequest, addCode, addFile})
"params": [
{
"flowVersion": "<VERSION STUBBED FOR TEST>",
"jsonVersion": "1",
"errors": [],
"passed": true
}
@@ -1178,6 +1186,7 @@ export default suite(({ideStart, ideNotification, ideRequest, addCode, addFile})
"params": [
{
"flowVersion": "<VERSION STUBBED FOR TEST>",
"jsonVersion": "1",
"errors": [
{
"kind": "lint",
@@ -1304,6 +1313,7 @@ export default suite(({ideStart, ideNotification, ideRequest, addCode, addFile})
"params": [
{
"flowVersion": "<VERSION STUBBED FOR TEST>",
"jsonVersion": "1",
"errors": [],
"passed": true
}
@@ -1322,6 +1332,7 @@ export default suite(({ideStart, ideNotification, ideRequest, addCode, addFile})
"params": [
{
"flowVersion": "<VERSION STUBBED FOR TEST>",
"jsonVersion": "1",
"errors": [
{
"kind": "lint",
@@ -1461,6 +1472,7 @@ export default suite(({ideStart, ideNotification, ideRequest, addCode, addFile})
"params": [
{
"flowVersion": "<VERSION STUBBED FOR TEST>",
"jsonVersion": "1",
"errors": [],
"passed": true
}
@@ -1483,6 +1495,7 @@ export default suite(({ideStart, ideNotification, ideRequest, addCode, addFile})
"params": [
{
"flowVersion": "<VERSION STUBBED FOR TEST>",
"jsonVersion": "1",
"errors": [],
"passed": true
}
@@ -1501,6 +1514,7 @@ export default suite(({ideStart, ideNotification, ideRequest, addCode, addFile})
"params": [
{
"flowVersion": "<VERSION STUBBED FOR TEST>",
"jsonVersion": "1",
"errors": [
{
"kind": "lint",
@@ -1623,6 +1637,7 @@ export default suite(({ideStart, ideNotification, ideRequest, addCode, addFile})
"params": [
{
"flowVersion": "<VERSION STUBBED FOR TEST>",
"jsonVersion": "1",
"errors": [],
"passed": true
}
Oops, something went wrong.

0 comments on commit 28c8a3e

Please sign in to comment.
You can’t perform that action at this time.