Skip to content

Commit 15b87c7

Browse files
committed
Improve linter message formatting
1 parent 61835a7 commit 15b87c7

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/linter.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export const expressionLanguageLinterSource = (state: EditorState) => {
2828
diagnostics.push({ from, to: node.node.parent?.parent?.to ?? to, severity: 'error', message: `Expression expected` });
2929
} else {
3030
const type = /^[a-zA-Z_]+[a-zA-Z_0-9]*$/.test(identifier) ? 'identifier' : 'operator';
31-
diagnostics.push({ from, to, severity: 'error', message: `Unexpected ${type} '${identifier}'` });
31+
diagnostics.push({ from, to, severity: 'error', message: `Unexpected ${type} <code>${identifier}</code>` });
3232
}
3333

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

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

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

8181
break;
8282
}
8383

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

test/test-linter.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ describe("Expression language linting", () => {
5454
const diagnostics = get("notfound / 5");
5555

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

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

7474
ist(diagnostics.length, 1);
75-
ist(diagnostics[0].message, "Unexpected identifier 'obj'");
75+
ist(diagnostics[0].message, "Unexpected identifier <code>obj</code>");
7676
ist(diagnostics[0].from, 4);
7777
ist(diagnostics[0].to, 7);
7878
});

0 commit comments

Comments
 (0)