unsplash / intlc

Compile ICU messages into code. Supports TypeScript and JSX. No runtime.
MIT License
56 stars 3 forks source link

Multiple error reporting #113

Closed samhh closed 2 years ago

samhh commented 2 years ago

Given:

{
  "f": {
    "message": "{x, bad1}"
  },
  "g": {
    "message": "{y, bad2}"
  }
}

We currently fail at the first sign of trouble:

$ intlc compile <file> -l <locale>
f:1:5:
  |
1 | {x, bad1}
  |     ^^^^^
unexpected "bad1}"
expecting "boolean", "date", "number", "plural", "select", "selectordinal", "time", or white space

Ideally we'd be able to continue trying to parse messages, collating all failures and reporting them together at the end:

$ intlc compile <file> -l <locale>
2 messages failed to compile:

f:1:5:
  |
1 | {x, bad1}
  |     ^^^^^
unexpected "bad1}"
expecting "boolean", "date", "number", "plural", "select", "selectordinal", "time", or white space

g:1:5:
  |
1 | {y, bad2}
  |     ^^^^^
unexpected "bad2}"
expecting "boolean", "date", "number", "plural", "select", "selectordinal", "time", or white space

Better yet the line numbers/etc could correlate to the JSON input:

$ intlc compile <file> -l <locale>
2 messages failed to compile:

<file>:3:5:
  |
3 |     "message": {x, bad1}
  |                    ^^^^^
unexpected "bad1}"
expecting "boolean", "date", "number", "plural", "select", "selectordinal", "time", or white space

<file>:6:5:
  |
6 |     "message": {y, bad2}
  |                    ^^^^^
unexpected "bad2}"
expecting "boolean", "date", "number", "plural", "select", "selectordinal", "time", or white space