fix(editor): don't flag an empty JSON editor as invalid

This commit is contained in:
Gregory Schier
2026-09-15 14:16:34 -07:00
parent edeb433c79
commit 0b6803c6c0
@@ -32,6 +32,8 @@ interface JsonLintOptions {
export function jsonParseLinter(options?: JsonLintOptions) { export function jsonParseLinter(options?: JsonLintOptions) {
return (view: EditorView): Diagnostic[] => { return (view: EditorView): Diagnostic[] => {
const doc = view.state.doc.toString(); const doc = view.state.doc.toString();
if (doc.trim() === "") return [];
// We need lint to not break on stuff like {"foo:" ${[ ... ]}} so we'll replace all template // We need lint to not break on stuff like {"foo:" ${[ ... ]}} so we'll replace all template
// syntax with repeating `1` characters, so it's valid JSON and the position is still correct. // syntax with repeating `1` characters, so it's valid JSON and the position is still correct.
const escapedDoc = doc.replace(TEMPLATE_SYNTAX_REGEX, (m) => "1".repeat(m.length)); const escapedDoc = doc.replace(TEMPLATE_SYNTAX_REGEX, (m) => "1".repeat(m.length));