Skip to content

Commit

Permalink
Improve linter message formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
valtzu committed Jan 12, 2025
1 parent 61835a7 commit 15b87c7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/linter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const expressionLanguageLinterSource = (state: EditorState) => {
diagnostics.push({ from, to: node.node.parent?.parent?.to ?? to, severity: 'error', message: `Expression expected` });
} else {
const type = /^[a-zA-Z_]+[a-zA-Z_0-9]*$/.test(identifier) ? 'identifier' : 'operator';
diagnostics.push({ from, to, severity: 'error', message: `Unexpected ${type} '${identifier}'` });
diagnostics.push({ from, to, severity: 'error', message: `Unexpected ${type} <code>${identifier}</code>` });
}

return;
Expand Down Expand Up @@ -66,7 +66,7 @@ export const expressionLanguageLinterSource = (state: EditorState) => {
identifier = state.sliceDoc(from, to);

if (!types.find(type => resolveIdentifier(id, identifier, config.types?.[type]))) {
diagnostics.push({ from, to, severity: 'error', message: `${node.name} "${identifier}" not found in ${types.join('|')}` });
diagnostics.push({ from, to, severity: 'error', message: `${node.name} <code>${identifier}</code> not found in <code>${types.join('|')}</code>` });
}

break;
Expand All @@ -75,14 +75,14 @@ export const expressionLanguageLinterSource = (state: EditorState) => {
case Function:
identifier = state.sliceDoc(from, node.node.firstChild ? node.node.firstChild.from - 1 : to);
if (!resolveIdentifier(id, identifier, config)) {
diagnostics.push({ from, to, severity: 'error', message: `${node.node.name} "${identifier}" not found` });
diagnostics.push({ from, to, severity: 'error', message: `${node.node.name} <code>${identifier}</code> not found` });
}

break;
}

if (identifier && node.node.parent?.type.isError) {
diagnostics.push({ from, to, severity: 'error', message: `Unexpected identifier "${identifier}"` });
diagnostics.push({ from, to, severity: 'error', message: `Unexpected identifier <code>${identifier}</code>` });
}
});

Expand Down
6 changes: 3 additions & 3 deletions test/test-linter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe("Expression language linting", () => {
const diagnostics = get("notfound / 5");

ist(diagnostics.length, 1);
ist(diagnostics[0].message, 'Variable "notfound" not found');
ist(diagnostics[0].message, 'Variable <code>notfound</code> not found');
ist(diagnostics[0].from, 0);
ist(diagnostics[0].to, 8);
});
Expand All @@ -63,7 +63,7 @@ describe("Expression language linting", () => {
const diagnostics = get("obj + notfound()");

ist(diagnostics.length, 1);
ist(diagnostics[0].message, 'Function "notfound" not found');
ist(diagnostics[0].message, 'Function <code>notfound</code> not found');
ist(diagnostics[0].from, 6);
ist(diagnostics[0].to, 14);
});
Expand All @@ -72,7 +72,7 @@ describe("Expression language linting", () => {
const diagnostics = get("obj obj");

ist(diagnostics.length, 1);
ist(diagnostics[0].message, "Unexpected identifier 'obj'");
ist(diagnostics[0].message, "Unexpected identifier <code>obj</code>");
ist(diagnostics[0].from, 4);
ist(diagnostics[0].to, 7);
});
Expand Down

0 comments on commit 15b87c7

Please sign in to comment.