@plumeria/eslint-plugin 16.2.0 → 16.2.1
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 +15 -0
- package/bin/oxlint.js +88 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -117,4 +117,19 @@ Example usage in `package.json`:
|
|
|
117
117
|
}
|
|
118
118
|
```
|
|
119
119
|
|
|
120
|
+
### Aborting Builds on Lint Errors (Parallel Pipeline)
|
|
121
|
+
|
|
122
|
+
You can run `plumerialint` in parallel with your build command (e.g. `next build` or `vite build`) using the `--` separator:
|
|
123
|
+
|
|
124
|
+
```json
|
|
125
|
+
{
|
|
126
|
+
"scripts": {
|
|
127
|
+
"build": "plumerialint -- next build"
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
If `plumerialint` detects any styling errors or warnings, it will print the diagnostics, kill the build process immediately, and exit with a non-zero code. This avoids compiling when styling validation fails.
|
|
133
|
+
|
|
120
134
|
**Note:** `oxlint` is required as `plumerialint` uses it internally.
|
|
135
|
+
|
package/bin/oxlint.js
CHANGED
|
@@ -3,15 +3,26 @@
|
|
|
3
3
|
const { spawn } = require('child_process');
|
|
4
4
|
const process = require('process');
|
|
5
5
|
const path = require('path');
|
|
6
|
-
const
|
|
6
|
+
const oxlintConfig = path.join(__dirname, '..', 'oxlint.json');
|
|
7
7
|
|
|
8
|
-
const
|
|
8
|
+
const doubleDashIndex = process.argv.indexOf('--');
|
|
9
|
+
let oxlintExtraArgs = [];
|
|
10
|
+
let buildCommand = null;
|
|
11
|
+
let buildArgs = [];
|
|
9
12
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
+
if (doubleDashIndex !== -1) {
|
|
14
|
+
oxlintExtraArgs = process.argv.slice(2, doubleDashIndex);
|
|
15
|
+
if (doubleDashIndex + 1 < process.argv.length) {
|
|
16
|
+
buildCommand = process.argv[doubleDashIndex + 1];
|
|
17
|
+
buildArgs = process.argv.slice(doubleDashIndex + 2);
|
|
18
|
+
}
|
|
19
|
+
} else {
|
|
20
|
+
oxlintExtraArgs = process.argv.slice(2);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const oxlintArgs = ['-c', oxlintConfig, '--deny-warnings', ...oxlintExtraArgs];
|
|
13
24
|
|
|
14
|
-
|
|
25
|
+
function handleOxlintError(err) {
|
|
15
26
|
if (err.code === 'ENOENT') {
|
|
16
27
|
console.error('\n✖ oxlint is not installed.');
|
|
17
28
|
console.error('➡︎ plumerialint uses oxlint.');
|
|
@@ -21,8 +32,75 @@ child.on('error', (err) => {
|
|
|
21
32
|
console.error('Error running oxlint:', err.message);
|
|
22
33
|
process.exit(1);
|
|
23
34
|
}
|
|
24
|
-
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (!buildCommand) {
|
|
38
|
+
const child = spawn('oxlint', oxlintArgs, { stdio: 'inherit' });
|
|
39
|
+
child.on('error', handleOxlintError);
|
|
40
|
+
child.on('close', (code) => {
|
|
41
|
+
process.exit(code || 0);
|
|
42
|
+
});
|
|
43
|
+
} else {
|
|
44
|
+
let oxlintExited = false;
|
|
45
|
+
let oxlintCode = null;
|
|
46
|
+
let buildExited = false;
|
|
47
|
+
let buildCode = null;
|
|
48
|
+
let aborted = false;
|
|
49
|
+
|
|
50
|
+
const oxlintChild = spawn('oxlint', oxlintArgs, { stdio: 'inherit' });
|
|
51
|
+
const buildChild = spawn(buildCommand, buildArgs, {
|
|
52
|
+
stdio: 'inherit',
|
|
53
|
+
shell: true,
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
function abort(exitCode, failedSource) {
|
|
57
|
+
if (aborted) return;
|
|
58
|
+
aborted = true;
|
|
59
|
+
|
|
60
|
+
if (failedSource === 'lint') {
|
|
61
|
+
console.error(`\n✖ [plumerialint] Linting failed. Aborting build...`);
|
|
62
|
+
try {
|
|
63
|
+
buildChild.kill();
|
|
64
|
+
} catch (e) {}
|
|
65
|
+
process.exit(exitCode || 1);
|
|
66
|
+
} else if (failedSource === 'build') {
|
|
67
|
+
console.error(`\n✖ [plumerialint] Build failed. Aborting lint...`);
|
|
68
|
+
try {
|
|
69
|
+
oxlintChild.kill();
|
|
70
|
+
} catch (e) {}
|
|
71
|
+
process.exit(exitCode || 1);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
oxlintChild.on('error', (err) => {
|
|
76
|
+
handleOxlintError(err);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
buildChild.on('error', (err) => {
|
|
80
|
+
console.error(
|
|
81
|
+
`Error running build command "${buildCommand}":`,
|
|
82
|
+
err.message,
|
|
83
|
+
);
|
|
84
|
+
abort(1, 'build');
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
oxlintChild.on('close', (code) => {
|
|
88
|
+
oxlintExited = true;
|
|
89
|
+
oxlintCode = code;
|
|
90
|
+
if (code !== 0) {
|
|
91
|
+
abort(code, 'lint');
|
|
92
|
+
} else if (buildExited) {
|
|
93
|
+
process.exit(buildCode || 0);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
25
96
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
97
|
+
buildChild.on('close', (code) => {
|
|
98
|
+
buildExited = true;
|
|
99
|
+
buildCode = code;
|
|
100
|
+
if (code !== 0) {
|
|
101
|
+
abort(code, 'build');
|
|
102
|
+
} else if (oxlintExited) {
|
|
103
|
+
process.exit(oxlintCode || 0);
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
}
|