Page MenuHomePhabricator

Improve the JSON linter
Closed, ResolvedPublicFeature

Description

Feature summary (what you would like to be able to do and where):

The current JSON linter relies on SyntaxError thrown by the native JSON.parse() function, which varies a lot across browsers. For example, Safari does not even report the location of the error.

In addition, the linter only reports real syntax problems, but duplicate object keys also deserve warnings. Since CodeEditor reports duplicate object keys (T373711#11494778), we may also want to implement it in CodeMirror.

Use case(s) (list the steps that you performed to discover that problem, and describe the actual underlying problem which you want to solve. Do not describe only a solution):

  • No error location:
  1. Open Safari/Chrome/Edge, and edit a JSON page with improved syntax highlighting (CodeMirror 6).
  2. Replace the content with [x], and the error is reported at the first character instead of before x like in Firefox.
  3. Another example [01] only fails in Safari, while Firefox/Chrome/Edge reports the error before 1.
  1. Edit a JSON page with improved syntax highlighting (CodeMirror 6).
  2. Replace the content with {"a": 0, "a": 1}, and no error or warning is reported.

Benefits (why should this be implemented?):

Error location is very useful information, and reports of duplicate object keys will also be helpful.

Event Timeline

Thanks. About the double keys, it may be not a syntax error, but it's definitely an error of losing data.

Change #1224582 had a related patch set uploaded (by Bhsd; author: Bhsd):

[mediawiki/extensions/CodeMirror@master] codemirror.json.parse.js: adapted JSON linter

https://gerrit.wikimedia.org/r/1224582

Change #1224582 merged by jenkins-bot:

[mediawiki/extensions/CodeMirror@master] codemirror.json.parse.js: adapted JSON linter

https://gerrit.wikimedia.org/r/1224582

Bhsd moved this task from Feature requests to Done on the MediaWiki-extensions-CodeMirror board.