@aklinker1/check 1.3.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/index.mjs +21 -6
- package/dist/tools/index.mjs +3 -2
- package/dist/tools/oxlint.d.ts +3 -0
- package/dist/tools/oxlint.mjs +42 -0
- package/dist/tools/oxlint.test.d.ts +1 -0
- package/dist/tools/oxlint.test.mjs +57 -0
- package/package.json +1 -1
package/README.md
CHANGED
package/dist/index.mjs
CHANGED
|
@@ -1,23 +1,38 @@
|
|
|
1
1
|
import { ALL_TOOLS } from "./tools/index.mjs";
|
|
2
2
|
import { p } from "@antfu/utils";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
bold,
|
|
5
|
+
cyan,
|
|
6
|
+
debug as debugLog,
|
|
7
|
+
dim,
|
|
8
|
+
humanMs,
|
|
9
|
+
isDebug,
|
|
10
|
+
red,
|
|
11
|
+
yellow
|
|
12
|
+
} from "./utils.mjs";
|
|
4
13
|
import { createTaskList } from "./tasklist/index.mjs";
|
|
5
14
|
import { relative, resolve, sep } from "node:path";
|
|
6
15
|
import { isCI } from "ci-info";
|
|
7
16
|
export async function check(options = {}) {
|
|
8
17
|
const {
|
|
9
|
-
debug
|
|
18
|
+
debug,
|
|
10
19
|
fix = !isCI,
|
|
11
20
|
root = process.cwd(),
|
|
12
21
|
binDir = "node_modules/.bin"
|
|
13
22
|
} = options;
|
|
14
|
-
if (
|
|
23
|
+
if (debug) {
|
|
15
24
|
process.env.DEBUG = "true";
|
|
16
25
|
}
|
|
17
26
|
console.log();
|
|
27
|
+
debugLog("Options:" + JSON.stringify(options));
|
|
28
|
+
debugLog("Resolved options:" + JSON.stringify({ debug, fix, root, binDir }));
|
|
18
29
|
const tools = await findInstalledTools({ root, binDir });
|
|
19
30
|
if (tools.length === 0) {
|
|
20
|
-
|
|
31
|
+
if (isDebug()) {
|
|
32
|
+
console.log("No tools detected!");
|
|
33
|
+
} else {
|
|
34
|
+
console.log("No tools detected! Run with --debug for more info");
|
|
35
|
+
}
|
|
21
36
|
console.log();
|
|
22
37
|
process.exit(1);
|
|
23
38
|
}
|
|
@@ -94,9 +109,9 @@ async function findInstalledTools(opts) {
|
|
|
94
109
|
if (isDebug()) {
|
|
95
110
|
const getTools = (isInstalled) => status.filter((item) => item.isInstalled === isInstalled).map((item) => item.tool.name).join(", ");
|
|
96
111
|
const installed = getTools(true);
|
|
97
|
-
|
|
112
|
+
debugLog(`Installed: ${installed || "(none)"}`);
|
|
98
113
|
const skipped = getTools(false);
|
|
99
|
-
|
|
114
|
+
debugLog(`Skipping: ${skipped || "(none)"} `);
|
|
100
115
|
}
|
|
101
116
|
return status.filter(({ isInstalled }) => isInstalled).map((item) => item.tool);
|
|
102
117
|
}
|
package/dist/tools/index.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { eslint } from "./eslint.mjs";
|
|
2
|
+
import { oxlint } from "./oxlint.mjs";
|
|
2
3
|
import { prettier } from "./prettier.mjs";
|
|
3
|
-
import { typescript } from "./typescript.mjs";
|
|
4
4
|
import { publint } from "./publint.mjs";
|
|
5
|
-
|
|
5
|
+
import { typescript } from "./typescript.mjs";
|
|
6
|
+
export const ALL_TOOLS = [publint, prettier, typescript, oxlint, eslint];
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { execAndParse, isBinInstalled } from "../utils.mjs";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
export const oxlint = ({ binDir, root }) => {
|
|
4
|
+
const bin = resolve(root, binDir, "oxlint");
|
|
5
|
+
const checkArgs = ["--format=linux"];
|
|
6
|
+
const fixArgs = ["--format=linux", "--fix"];
|
|
7
|
+
return {
|
|
8
|
+
name: "Oxlint",
|
|
9
|
+
isInstalled: () => isBinInstalled(bin),
|
|
10
|
+
check: () => execAndParse(bin, checkArgs, root, parseOuptut),
|
|
11
|
+
fix: () => execAndParse(bin, fixArgs, root, parseOuptut)
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
export const parseOuptut = ({ stdout, stderr }) => {
|
|
15
|
+
if (stdout.trim()) {
|
|
16
|
+
return stdout.split(/\r?\n/).reduce((acc, line) => {
|
|
17
|
+
const groups = /^(?<file>.+?):(?<line>[0-9]+):(?<column>[0-9]):\s?(?<message>.*?)\s?\[(?<kind>Warning|Error)\/?(?<rule>.*?)\]\s?$/.exec(
|
|
18
|
+
line
|
|
19
|
+
)?.groups;
|
|
20
|
+
if (groups) {
|
|
21
|
+
acc.push({
|
|
22
|
+
file: groups.file,
|
|
23
|
+
kind: groups.kind === "Error" ? "error" : "warning",
|
|
24
|
+
message: groups.message,
|
|
25
|
+
rule: groups.rule || void 0,
|
|
26
|
+
location: {
|
|
27
|
+
line: parseInt(groups.line, 10),
|
|
28
|
+
column: parseInt(groups.column, 10)
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
return acc;
|
|
33
|
+
}, []);
|
|
34
|
+
}
|
|
35
|
+
return stdout.trim().split(/\r?\n/).map((line) => line.trim()).filter((line) => !!line && !line.includes(" ")).map(
|
|
36
|
+
(line) => ({
|
|
37
|
+
file: line.trim(),
|
|
38
|
+
kind: "warning",
|
|
39
|
+
message: "Not formatted."
|
|
40
|
+
})
|
|
41
|
+
);
|
|
42
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { describe, it, expect } from "bun:test";
|
|
2
|
+
import { parseOuptut } from "./oxlint.mjs";
|
|
3
|
+
describe("Oxlint", () => {
|
|
4
|
+
it("should properly parse output", async () => {
|
|
5
|
+
const stdout = `
|
|
6
|
+
test.ts:1:7: Variable 'test' is declared but never used. [Warning/eslint(no-unused-vars)]
|
|
7
|
+
test.ts:3:7: Variable 'variable' is declared but never used. [Warning/eslint(no-unused-vars)]
|
|
8
|
+
test.ts:8:7: Variable 'two' is declared but never used. [Warning/eslint(no-unused-vars)]
|
|
9
|
+
test.ts:8:7: Missing initializer in const declaration [Error]
|
|
10
|
+
|
|
11
|
+
3 problems
|
|
12
|
+
`;
|
|
13
|
+
const stderr = "";
|
|
14
|
+
const code = 1;
|
|
15
|
+
expect(parseOuptut({ code, stdout, stderr })).toEqual([
|
|
16
|
+
{
|
|
17
|
+
file: "test.ts",
|
|
18
|
+
message: "Variable 'test' is declared but never used.",
|
|
19
|
+
location: {
|
|
20
|
+
line: 1,
|
|
21
|
+
column: 7
|
|
22
|
+
},
|
|
23
|
+
rule: "eslint(no-unused-vars)",
|
|
24
|
+
kind: "warning"
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
file: "test.ts",
|
|
28
|
+
message: "Variable 'variable' is declared but never used.",
|
|
29
|
+
location: {
|
|
30
|
+
line: 3,
|
|
31
|
+
column: 7
|
|
32
|
+
},
|
|
33
|
+
rule: "eslint(no-unused-vars)",
|
|
34
|
+
kind: "warning"
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
file: "test.ts",
|
|
38
|
+
message: "Variable 'two' is declared but never used.",
|
|
39
|
+
location: {
|
|
40
|
+
line: 8,
|
|
41
|
+
column: 7
|
|
42
|
+
},
|
|
43
|
+
rule: "eslint(no-unused-vars)",
|
|
44
|
+
kind: "warning"
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
file: "test.ts",
|
|
48
|
+
message: "Missing initializer in const declaration",
|
|
49
|
+
location: {
|
|
50
|
+
line: 8,
|
|
51
|
+
column: 7
|
|
52
|
+
},
|
|
53
|
+
kind: "error"
|
|
54
|
+
}
|
|
55
|
+
]);
|
|
56
|
+
});
|
|
57
|
+
});
|