Skip to content

Commit 2a986bc

Browse files
committed
fix: loosen up regex for problem matcher
1 parent 41aa15b commit 2a986bc

File tree

3 files changed

+44
-15
lines changed

3 files changed

+44
-15
lines changed

.github/svelte-check-matcher.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"column": 3
1111
},
1212
{
13-
"regexp": "^\\s*(Error|Warning):\\s*(.*)\\s+\\((?:ts|js|svelte)\\)$",
13+
"regexp": "^\\s*(Error|Warning|Warn):\\s*(.*?)(?:\\s+\\((?:ts|js|svelte|css)\\))?$",
1414
"severity": 1,
1515
"message": 2,
1616
"loop": false

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "gha-svelte-check",
3-
"version": "1.1.1",
3+
"version": "1.1.2",
44
"description": "GitHub Action for running svelte-check with problem matcher",
55
"main": "dist/index.js",
66
"scripts": {

src/index.ts

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,52 @@ function stripAnsi(input: string): string {
77
return input.replace(/[\u001B\u009B][[()\]#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, '');
88
}
99

10-
function annotateFromOutput(output: string, workingDirectory: string) {
10+
function parseFindings(output: string, workingDirectory: string) {
1111
const clean = stripAnsi(output);
12-
const re = /^(.+?):(\d+):(\d+)\s+(Error|Warning|Hint):\s+(.*)$/gm;
12+
const lines = clean.split(/\r?\n/);
13+
14+
type Finding = {
15+
severity: 'Error' | 'Warning' | 'Hint';
16+
message: string;
17+
file: string;
18+
line: number;
19+
col: number;
20+
};
21+
22+
const findings: Finding[] = [];
23+
24+
for (let i = 0; i < lines.length; i++) {
25+
const loc = lines[i].match(/^(.+?):(\d+):(\d+)$/);
26+
if (!loc) continue;
27+
28+
const [, relFile, lineStr, colStr] = loc;
29+
const next = lines[i + 1] || '';
30+
const sevLine = next.match(/^\s*(Error|Warning|Warn|Hint):\s*(.*?)(?:\s+\([^)]+\))?$/);
31+
if (!sevLine) continue;
1332

14-
let match: RegExpExecArray | null;
15-
while ((match = re.exec(clean))) {
16-
const [, relFile, lineStr, colStr, sev, message] = match;
33+
let sev = sevLine[1] as 'Error' | 'Warning' | 'Hint' | 'Warn';
34+
const message = sevLine[2];
35+
36+
if (sev === 'Warn') sev = 'Warning';
1737
const filePath = path.normalize(path.join(workingDirectory, relFile));
1838
const line = parseInt(lineStr, 10) || 1;
1939
const col = parseInt(colStr, 10) || 1;
2040

21-
const props = { file: filePath, startLine: line, startColumn: col, title: 'svelte-check' as const };
41+
findings.push({ severity: sev as 'Error' | 'Warning' | 'Hint', message, file: filePath, line, col });
42+
}
2243

23-
if (sev === 'Error') core.error(message, props);
24-
else if (sev === 'Warning') core.warning(message, props);
25-
else core.notice(message, props);
44+
return findings;
45+
}
46+
47+
function annotateFromOutput(output: string, workingDirectory: string) {
48+
const findings = parseFindings(output, workingDirectory);
49+
for (const f of findings) {
50+
const props = { file: f.file, startLine: f.line, startColumn: f.col, title: 'svelte-check' as const };
51+
if (f.severity === 'Error') core.error(f.message, props);
52+
else if (f.severity === 'Warning') core.warning(f.message, props);
53+
else core.notice(f.message, props);
2654
}
55+
return findings;
2756
}
2857

2958
async function run(): Promise<void> {
@@ -87,11 +116,11 @@ async function run(): Promise<void> {
87116
const exitCode = await exec.exec(npx, args, options);
88117
core.info(`svelte-check exit code: ${exitCode}`);
89118

90-
annotateFromOutput(output + '\n' + errorOutput, workingDirectory);
119+
const findings = annotateFromOutput(output + '\n' + errorOutput, workingDirectory);
91120

92-
const errorCount = (output.match(/Error:/g) || []).length;
93-
const warningCount = (output.match(/Warning:/g) || []).length;
94-
const hintCount = (output.match(/Hint:/g) || []).length;
121+
const errorCount = findings.filter((f) => f.severity === 'Error').length;
122+
const warningCount = findings.filter((f) => f.severity === 'Warning').length;
123+
const hintCount = findings.filter((f) => f.severity === 'Hint').length;
95124

96125
core.setOutput('errors', String(errorCount));
97126
core.setOutput('warnings', String(warningCount));

0 commit comments

Comments
 (0)