@cloudpss/lint-staged-config 3.0.0 → 3.0.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/index.js +13 -12
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -35,7 +35,7 @@ const isEslintFile = async (f) => {
|
|
|
35
35
|
* @param {string[]} commands 命令列表
|
|
36
36
|
* @returns {string[]}
|
|
37
37
|
*/
|
|
38
|
-
function makeCommands(files, commands) {
|
|
38
|
+
function makeCommands(files, ...commands) {
|
|
39
39
|
if (files.length === 0) return [];
|
|
40
40
|
const fileLine = ` -- '${files.join(`' '`)}'`;
|
|
41
41
|
return commands.map((c) => c + fileLine);
|
|
@@ -63,23 +63,24 @@ function handler(impl) {
|
|
|
63
63
|
export default /** @type {import('lint-staged').Config} */ ({
|
|
64
64
|
'*': handler(async (files) => {
|
|
65
65
|
const commands = [];
|
|
66
|
+
const allFiles = [];
|
|
66
67
|
const eslintFiles = [];
|
|
67
68
|
const prettierFiles = [];
|
|
68
69
|
for (const file of files) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
70
|
+
const eslint = await isEslintFile(file);
|
|
71
|
+
const prettier = await isPrettierFile(file);
|
|
72
|
+
if (eslint) eslintFiles.push(file);
|
|
73
|
+
if (prettier) prettierFiles.push(file);
|
|
74
|
+
if (eslint || prettier) allFiles.push(file);
|
|
74
75
|
}
|
|
75
|
-
|
|
76
76
|
const cacheOptions = `--cache --cache-strategy content`;
|
|
77
77
|
commands.push(
|
|
78
|
-
...makeCommands(
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
78
|
+
...makeCommands(prettierFiles, `prettier ${cacheOptions} --write`),
|
|
79
|
+
...makeCommands(
|
|
80
|
+
eslintFiles,
|
|
81
|
+
`eslint ${cacheOptions} --cache-location node_modules/.cache/eslint/ --fix --max-warnings 0 --no-error-on-unmatched-pattern`,
|
|
82
|
+
),
|
|
83
|
+
...makeCommands(allFiles, `git add`),
|
|
83
84
|
);
|
|
84
85
|
return commands;
|
|
85
86
|
}),
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"homepage": "https://cloudpss.net/",
|
|
5
5
|
"repository": "https://codeup.aliyun.com/cloudpss/code-quality.git",
|
|
6
|
-
"version": "3.0.
|
|
6
|
+
"version": "3.0.1",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"main": "./index.js",
|
|
9
9
|
"exports": "./index.js",
|
|
@@ -12,4 +12,4 @@
|
|
|
12
12
|
"lint-staged": "^15.2.8",
|
|
13
13
|
"prettier": "^3.3.3"
|
|
14
14
|
}
|
|
15
|
-
}
|
|
15
|
+
}
|