unsplash / intlc

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

Print more error context #116

Open samhh opened 2 years ago

samhh commented 2 years ago

Off the back of #114/#115, it'd be great to have more lines/context around errors. Example:

./x-all.json:6:21:
  |
6 |     "message": "{x, bad}"
  |                     ^^^^^^
unexpected "bad}"<newline>  },<newline>  "
expecting "boolean", "date", "number", "plural", "select", "selectordinal", "time", or white space

I can see the line number and the problem itself, which is good, however ideally it'd also show the line above with the translation name. In an ideal world we would always show everything in the object:

./x-all.json:6:21:
  |
5 |   "f": {
6 |     "message": "{x, bad}"
  |                     ^^^^^^
7 |   }
  |
unexpected "bad}"<newline>  },<newline>  "
expecting "boolean", "date", "number", "plural", "select", "selectordinal", "time", or white space
samhh commented 1 year ago

This is relevant to linting output as well as of #179.

It's unclear how well this would scale. The object may be large and the message mayn't be at the top.