@utoo/lint 0.0.2

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/bin/eslint.js ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env node
2
+ import { spawnSync } from "node:child_process";
3
+ import { fileURLToPath } from "node:url";
4
+
5
+ const fishlint = fileURLToPath(new URL("./fishlint.js", import.meta.url));
6
+ const result = spawnSync(process.execPath, [fishlint, "eslint", ...process.argv.slice(2)], {
7
+ stdio: "inherit"
8
+ });
9
+
10
+ if (result.error) {
11
+ console.error(`utoo-lint: failed to run eslint compatibility wrapper: ${result.error.message}`);
12
+ process.exit(1);
13
+ }
14
+
15
+ process.exit(result.status ?? 1);
@@ -0,0 +1,58 @@
1
+ #!/usr/bin/env node
2
+ import { spawnSync } from "node:child_process";
3
+ import { existsSync } from "node:fs";
4
+ import { join } from "node:path";
5
+ import { fileURLToPath } from "node:url";
6
+
7
+ const localLintStaged = join(
8
+ process.cwd(),
9
+ "node_modules",
10
+ ".bin",
11
+ process.platform === "win32" ? "lint-staged.cmd" : "lint-staged"
12
+ );
13
+
14
+ if (existsSync(localLintStaged)) {
15
+ const result = spawnSync(localLintStaged, process.argv.slice(2), { stdio: "inherit" });
16
+ if (result.error) {
17
+ console.error(`utoo-lint: failed to run lint-staged: ${result.error.message}`);
18
+ process.exit(1);
19
+ }
20
+ process.exit(result.status ?? 1);
21
+ }
22
+
23
+ const staged = spawnSync("git", ["diff", "--name-only", "--cached", "--diff-filter=ACMRTUB"], {
24
+ encoding: "utf8"
25
+ });
26
+
27
+ if (staged.error) {
28
+ console.error(`utoo-lint: failed to read staged files: ${staged.error.message}`);
29
+ process.exit(1);
30
+ }
31
+ if (staged.status !== 0) {
32
+ process.stderr.write(staged.stderr ?? "");
33
+ process.exit(staged.status ?? 1);
34
+ }
35
+
36
+ const files = staged.stdout
37
+ .split(/\r?\n/)
38
+ .filter((file) => file.length > 0 && isLintableScript(file));
39
+
40
+ if (files.length === 0) {
41
+ process.exit(0);
42
+ }
43
+
44
+ const fishlint = fileURLToPath(new URL("./fishlint.js", import.meta.url));
45
+ const result = spawnSync(process.execPath, [fishlint, "eslint", ...process.argv.slice(2), ...files], {
46
+ stdio: "inherit"
47
+ });
48
+
49
+ if (result.error) {
50
+ console.error(`utoo-lint: failed to run fishlint-lint-staged fallback: ${result.error.message}`);
51
+ process.exit(1);
52
+ }
53
+
54
+ process.exit(result.status ?? 1);
55
+
56
+ function isLintableScript(file) {
57
+ return /\.(?:[cm]?[jt]sx?)$/.test(file);
58
+ }