@cloudpss/lint-staged-config 2.1.3 → 3.0.0-rc.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.d.ts +2 -0
- package/index.js +5 -31
- package/package.json +6 -5
package/index.d.ts
ADDED
package/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/* eslint-disable no-console */
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
import { getFileInfo } from 'prettier';
|
|
4
|
+
import { loadESLint } from 'eslint';
|
|
4
5
|
|
|
5
|
-
const
|
|
6
|
-
const eslintCli = new (require('eslint').ESLint)({});
|
|
6
|
+
const eslintCli = new (await loadESLint({ useFlatConfig: true }))();
|
|
7
7
|
|
|
8
8
|
const DEBUG = (process.env['DEBUG'] ?? '').includes('lint-staged-config');
|
|
9
9
|
|
|
@@ -12,7 +12,7 @@ const DEBUG = (process.env['DEBUG'] ?? '').includes('lint-staged-config');
|
|
|
12
12
|
* @param {string} f 文件路径
|
|
13
13
|
*/
|
|
14
14
|
const isPrettierFile = async (f) => {
|
|
15
|
-
const fileInfo = await
|
|
15
|
+
const fileInfo = await getFileInfo(f, {
|
|
16
16
|
ignorePath: ['.prettierignore', '.gitignore'],
|
|
17
17
|
resolveConfig: false,
|
|
18
18
|
});
|
|
@@ -24,28 +24,9 @@ const isPrettierFile = async (f) => {
|
|
|
24
24
|
* @param {string} f 文件路径
|
|
25
25
|
*/
|
|
26
26
|
const isEslintFile = async (f) => {
|
|
27
|
-
const ext = path.extname(f);
|
|
28
|
-
if (!ext || !['.js', '.jsx', '.ts', '.tsx', '.vue'].includes(ext)) return false;
|
|
29
27
|
return !(await eslintCli.isPathIgnored(f));
|
|
30
28
|
};
|
|
31
29
|
|
|
32
|
-
/**
|
|
33
|
-
* 检查文件是否是 stylelint 支持的文件
|
|
34
|
-
* @param {string} f 文件路径
|
|
35
|
-
*/
|
|
36
|
-
const isStylelintFile = (() => {
|
|
37
|
-
try {
|
|
38
|
-
require.resolve('stylelint');
|
|
39
|
-
return (/** @type {string} */ f) => {
|
|
40
|
-
const ext = path.extname(f);
|
|
41
|
-
if (!ext || !['.css', '.scss', '.sass'].includes(ext)) return false;
|
|
42
|
-
return true;
|
|
43
|
-
};
|
|
44
|
-
} catch {
|
|
45
|
-
return () => false;
|
|
46
|
-
}
|
|
47
|
-
})();
|
|
48
|
-
|
|
49
30
|
/**
|
|
50
31
|
* 生成命令
|
|
51
32
|
* @param {string[]} files 文件列表
|
|
@@ -76,17 +57,14 @@ function handler(impl) {
|
|
|
76
57
|
};
|
|
77
58
|
}
|
|
78
59
|
|
|
79
|
-
|
|
60
|
+
export default /** @type {import('lint-staged').Config} */ ({
|
|
80
61
|
'*': handler(async (files) => {
|
|
81
62
|
const commands = [];
|
|
82
63
|
const eslintFiles = [];
|
|
83
|
-
const stylelintFiles = [];
|
|
84
64
|
const prettierFiles = [];
|
|
85
65
|
for (const file of files) {
|
|
86
66
|
if (await isEslintFile(file)) {
|
|
87
67
|
eslintFiles.push(file);
|
|
88
|
-
} else if (isStylelintFile(file)) {
|
|
89
|
-
stylelintFiles.push(file);
|
|
90
68
|
} else if (await isPrettierFile(file)) {
|
|
91
69
|
prettierFiles.push(file);
|
|
92
70
|
}
|
|
@@ -98,10 +76,6 @@ module.exports = /** @type {import('lint-staged').Config} */ ({
|
|
|
98
76
|
`eslint ${cacheOptions} --cache-location node_modules/.cache/eslint/ --fix --max-warnings 0 --no-error-on-unmatched-pattern`,
|
|
99
77
|
`git add`,
|
|
100
78
|
]),
|
|
101
|
-
...makeCommands(stylelintFiles, [
|
|
102
|
-
`stylelint ${cacheOptions} --cache-location node_modules/.cache/stylelint/ --fix`,
|
|
103
|
-
`git add`,
|
|
104
|
-
]),
|
|
105
79
|
...makeCommands(prettierFiles, [`prettier ${cacheOptions} --write`, `git add`]),
|
|
106
80
|
);
|
|
107
81
|
return commands;
|
package/package.json
CHANGED
|
@@ -3,12 +3,13 @@
|
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"homepage": "https://cloudpss.net/",
|
|
5
5
|
"repository": "https://codeup.aliyun.com/cloudpss/code-quality.git",
|
|
6
|
-
"version": "
|
|
7
|
-
"type": "
|
|
6
|
+
"version": "3.0.0-rc.1",
|
|
7
|
+
"type": "module",
|
|
8
8
|
"main": "./index.js",
|
|
9
|
+
"exports": "./index.js",
|
|
9
10
|
"dependencies": {
|
|
10
|
-
"eslint": "^8.
|
|
11
|
-
"lint-staged": "^15.2.
|
|
12
|
-
"prettier": "^3.3.
|
|
11
|
+
"eslint": "^9.8.0",
|
|
12
|
+
"lint-staged": "^15.2.8",
|
|
13
|
+
"prettier": "^3.3.3"
|
|
13
14
|
}
|
|
14
15
|
}
|