Skip to content

Commit f2cb710

Browse files
committed
Extract warning/error regexes to constants and simplify detection
Each regex was duplicated: once for the whole-string check and once for findIndex. Now we just do findIndex directly — if it finds a match, we know both the result and the line number in one pass. https://claude.ai/code/session_01Eph17CQCfdnKaJhA2nSr9W
1 parent 7fbccad commit f2cb710

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

src/index.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,22 @@ for (const file of readdirRecursively(".")) {
6868

6969
const compilationOutput = readFileSync(file).toString();
7070

71+
const warningRegex = /warning( .\d+)?:/;
72+
const errorRegex = /error( .\d+)?:/;
73+
7174
let compileResult = "✅success";
7275
let firstIssueLine = 1;
7376
const lines = compilationOutput.split("\n");
74-
if (compilationOutput.match(/warning( .\d+)?:/)) {
77+
const warningIdx = lines.findIndex((line) => line.match(warningRegex));
78+
if (warningIdx !== -1) {
7579
compileResult = "⚠️warning";
76-
const idx = lines.findIndex((line) => line.match(/warning( .\d+)?:/));
77-
if (idx !== -1) firstIssueLine = idx + 1;
78-
} else if (compilationOutput.match(/error( .\d+)?:/)) {
79-
compileResult = "❌error";
80-
const idx = lines.findIndex((line) => line.match(/error( .\d+)?:/));
81-
if (idx !== -1) firstIssueLine = idx + 1;
80+
firstIssueLine = warningIdx + 1;
81+
} else {
82+
const errorIdx = lines.findIndex((line) => line.match(errorRegex));
83+
if (errorIdx !== -1) {
84+
compileResult = "❌error";
85+
firstIssueLine = errorIdx + 1;
86+
}
8287
}
8388

8489
const { data: job } = await octokit.rest.actions.getJobForWorkflowRun({

0 commit comments

Comments
 (0)