Skip to content

Commit 8edd47f

Browse files
committed
eslint improvments
1 parent 0bb66e4 commit 8edd47f

File tree

6 files changed

+197
-8
lines changed

6 files changed

+197
-8
lines changed

dist/index.js

Lines changed: 93 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import { cwd, chdir } from "process";
1010
import minimist from "minimist";
1111
import { setup } from "./scripts/setup";
1212

13+
export type Command = { label: string; command: string };
14+
1315
export type stepResponse = { output: string; error: boolean };
1416
export const failedEmoji = "❌";
1517
export const passedEmoji = "✅";
@@ -114,6 +116,10 @@ export async function run(): Promise<void> {
114116
? await analyze()
115117
: undefined;
116118

119+
const eslintStr: stepResponse | undefined = doStaticAnalysis
120+
? await eslint({ label: "ESLint", command: "npm run lint" })
121+
: undefined;
122+
117123
// run Code Formatting
118124
const codeFormattingStr: stepResponse | undefined = doCodeFormatting
119125
? await formatting()
@@ -136,6 +142,7 @@ export async function run(): Promise<void> {
136142
context,
137143
setupStr,
138144
analyzeStr,
145+
eslintStr,
139146
codeFormattingStr,
140147
testingStr,
141148
);
@@ -145,3 +152,49 @@ export async function run(): Promise<void> {
145152
if (error instanceof Error) setFailed(error.message);
146153
}
147154
}
155+
156+
const eslint = async (command: Command): Promise<stepResponse> => {
157+
let response: stepResponse = { output: "", error: false };
158+
let outputStr = "";
159+
let error = false;
160+
try {
161+
await exec(command.command, [], {
162+
listeners: {
163+
stdout: (data) => {
164+
outputStr += data.toString();
165+
},
166+
stderr: (data) => {
167+
outputStr += data.toString();
168+
},
169+
},
170+
});
171+
} catch (error) {
172+
error = true;
173+
setFailed(`Failed ${command.label}: ${error}`);
174+
}
175+
176+
if (error) {
177+
response.error = true;
178+
// Parse the output to find errors and problems
179+
const lines = outputStr.split("\n");
180+
const table = lines
181+
.map((line) => {
182+
const match = line.match(/^(.*?):(\d+):(\d+): (.*)$/);
183+
if (match) {
184+
const [_, file, line, column, message] = match;
185+
return `<tr><td>${file}</td><td>${line}</td><td>${column}</td><td>${message}</td></tr>`;
186+
}
187+
return "";
188+
})
189+
.join("");
190+
191+
const problemCount = lines.filter((line) =>
192+
line.match(/^(.*?):(\d+):(\d+): (.*)$/),
193+
).length;
194+
response.output = `<p>${problemCount} problem${problemCount !== 1 ? "s" : ""} found</p><details><summary>See Details</summary><table><tr><th>File</th><th>Line</th><th>Column</th><th>Message</th></tr>${table}</table></details>`;
195+
return response;
196+
} else {
197+
response.output = `<li>${passedEmoji} - ${command.label}\n</li>`;
198+
return response;
199+
}
200+
};

src/scripts/analyze.ts

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { setFailed } from "@actions/core";
2-
import { stepResponse, buildComment } from "src/main";
2+
import { exec } from "@actions/exec";
3+
import { stepResponse, buildComment, Command, passedEmoji } from "src/main";
34

45
export const analyze = async (): Promise<stepResponse> => {
56
const commands = [
67
{ label: "Custom Elements Manifest Analyzer", command: "npm run analyze" },
7-
{ label: "ESLint", command: "npm run lint" },
88
{ label: "Lit Analyzer", command: "npm run lint:lit-analyzer" },
99
];
1010

@@ -17,3 +17,48 @@ export const analyze = async (): Promise<stepResponse> => {
1717
return { output: commentBody.trim(), error: false };
1818
}
1919
};
20+
21+
// export const buildComment = async (
22+
// commands: { label: string; command: string }[],
23+
// ): Promise<string[]> => {
24+
// let commentBody = "\n";
25+
// let errorMessages = "";
26+
// for (const { label, command } of commands) {
27+
// const result = await runCommand(command, label);
28+
// if (result) {
29+
// commentBody += `<li>${failedEmoji} - ${label}
30+
// <details><summary>See details</summary>${result}</details></li>`;
31+
// errorMessages += `${result}`;
32+
// } else {
33+
// commentBody += `<li>${passedEmoji} - ${label}\n</li>`;
34+
// }
35+
// }
36+
// return [commentBody, errorMessages];
37+
// };
38+
39+
// export const runCommand = async (
40+
// command: string,
41+
// label: string,
42+
// ): Promise<string | boolean> => {
43+
// let output = "";
44+
// try {
45+
// await exec(command, [], {
46+
// listeners: {
47+
// stdout: (data) => {
48+
// output += data.toString();
49+
// },
50+
// },
51+
// });
52+
// return false;
53+
// } catch (error: unknown) {
54+
// if (error instanceof Error) {
55+
// debug(`${label} failed: ${error.message}`);
56+
// return output;
57+
// } else if (typeof error === "string") {
58+
// debug(`${label} failed: ${error}`);
59+
// return output;
60+
// } else {
61+
// return true;
62+
// }
63+
// }
64+
// };

src/scripts/comment.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export const comment = async (
88
context: Context,
99
setupStr: stepResponse | undefined,
1010
analyzeStr: stepResponse | undefined,
11+
eslintStr: stepResponse | undefined,
1112
codeFormattingStr: stepResponse | undefined,
1213
testingStr: stepResponse | undefined,
1314
): Promise<stepResponse> => {
@@ -17,6 +18,7 @@ export const comment = async (
1718
<ul>
1819
${setupStr?.output}
1920
${analyzeStr?.output}
21+
${eslintStr?.output}
2022
${codeFormattingStr?.output}
2123
${testingStr?.output}
2224
</ul>`;

src/scripts/testing.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export const testing = async (): Promise<stepResponse> => {
4242
label: "Install PlayWright Browsers",
4343
command: "npx playwright install --with-deps",
4444
},
45-
{ label: "Testing", command: "npm run test" },
45+
{ label: "Testing", command: "npm run test -- --coverage" },
4646
{ label: "TSDoc", command: "npm run docs" },
4747
];
4848

0 commit comments

Comments
 (0)