Add json parse linter to json-lang package #316

Merged
PhilippRaab merged 3 commits from json-parse-linter into master 2020-10-20 09:57:51 +02:00
PhilippRaab commented 2020-10-16 10:49:45 +02:00 (Migrated from github.com)
No description provided.
marijnh commented 2020-10-16 10:56:14 +02:00 (Migrated from github.com)

This seems to assume V8's error message format (for example, Firefox emits something like "SyntaxError: JSON.parse: expected double-quoted property name at line 1 column 12 of the JSON data"). It'd be good to at least cover all major browsers.

Also, can't you just use state.doc.toString() instead of the Array.from invocation that you have there? state.doc is never null, so the ?? is superfluous too.

This seems to assume V8's error message format (for example, Firefox emits something like "SyntaxError: JSON.parse: expected double-quoted property name at line 1 column 12 of the JSON data"). It'd be good to at least cover all major browsers. Also, can't you just use `state.doc.toString()` instead of the `Array.from` invocation that you have there? `state.doc` is never null, so the `??` is superfluous too.
PhilippRaab commented 2020-10-16 11:57:09 +02:00 (Migrated from github.com)

Tested in Chrome, Firefox, Opera and Edge with the latest versions. I am not able to test on Safari or IE.

Tested in Chrome, Firefox, Opera and Edge with the latest versions. I am not able to test on Safari or IE.
mischnic commented 2020-10-16 12:02:11 +02:00 (Migrated from github.com)

Safari 13 macOS:

> try{ JSON.parse("{'X': 2}"); } catch(e){ console.log(e.message); }
JSON Parse error: Single quotes (') are not allowed in JSON
Safari 13 macOS: ``` > try{ JSON.parse("{'X': 2}"); } catch(e){ console.log(e.message); } JSON Parse error: Single quotes (') are not allowed in JSON ```
PhilippRaab commented 2020-10-16 12:12:08 +02:00 (Migrated from github.com)

Safari 13 macOS:

> try{ JSON.parse("{'X': 2}"); } catch(e){ console.log(e.message); }
JSON Parse error: Single quotes (') are not allowed in JSON

Thanks!
It should work as well, but the error is shown on position 0 all the time.

Edit: Not sure if this linter makes sense, since the behavior is not consistent on all browsers. It probably makes more sense to base the linting on the lezer syntax or a third party lib. What do you think about that @marijnh ?

> Safari 13 macOS: > > ``` > > try{ JSON.parse("{'X': 2}"); } catch(e){ console.log(e.message); } > JSON Parse error: Single quotes (') are not allowed in JSON > ``` Thanks! It should work as well, but the error is shown on position 0 all the time. Edit: Not sure if this linter makes sense, since the behavior is not consistent on all browsers. It probably makes more sense to base the linting on the lezer syntax or a third party lib. What do you think about that @marijnh ?
marijnh commented 2020-10-16 12:59:15 +02:00 (Migrated from github.com)

Thanks. Two more nitpicks: this project uses semicolon-less style, and we target IE11, which doesn't have Number.isNaN. But since \d+ will only ever match integers, the check seems unnecessary in general.

Thanks. Two more nitpicks: this project uses semicolon-less style, and we target IE11, which doesn't have `Number.isNaN`. But since `\d+` will only ever match integers, the check seems unnecessary in general.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
codemirror/dev!316
No description provided.