From 2f8aa79ec1f3e84b6a342e7ce3f2c134dba84643 Mon Sep 17 00:00:00 2001 From: Andrew Bastin Date: Mon, 6 Sep 2021 23:47:26 +0530 Subject: [PATCH] feat: json linter support for codemirror --- helpers/editor/linting/json.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 helpers/editor/linting/json.ts diff --git a/helpers/editor/linting/json.ts b/helpers/editor/linting/json.ts new file mode 100644 index 000000000..46a690197 --- /dev/null +++ b/helpers/editor/linting/json.ts @@ -0,0 +1,21 @@ +import { convertIndexToLineCh } from "../utils" +import { LinterDefinition, LinterResult } from "./linter" +import jsonParse from "~/helpers/jsonParse" + +const linter: LinterDefinition = (text) => { + try { + jsonParse(text) + return Promise.resolve([]) + } catch (e: any) { + return Promise.resolve([ + { + from: convertIndexToLineCh(text, e.start), + to: convertIndexToLineCh(text, e.end), + message: e.message, + severity: "error", + }, + ]) + } +} + +export default linter