@cloudpss/lint-staged-config 1.4.4 → 1.5.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.
Files changed (2) hide show
  1. package/index.js +14 -13
  2. package/package.json +4 -4
package/index.js CHANGED
@@ -2,15 +2,22 @@
2
2
 
3
3
  const path = require('node:path');
4
4
 
5
- const prettierSupportInfo = require('prettier').getSupportInfo();
5
+ const prettier = require('prettier');
6
6
  const eslintCli = new (require('eslint').ESLint)({});
7
7
 
8
8
  const DEBUG = (process.env['DEBUG'] ?? '').includes('lint-staged-config');
9
9
 
10
- /** @type {ReadonlyArray<string>} */
11
- const prettierSupportedExt = prettierSupportInfo.languages.flatMap((l) => l.extensions ?? []);
12
- /** @type {ReadonlyArray<string>} */
13
- const prettierSupportedFilename = prettierSupportInfo.languages.flatMap((l) => l.filenames ?? []);
10
+ /**
11
+ * 检查文件是否是 prettier 支持的文件
12
+ * @param {string} f 文件路径
13
+ */
14
+ const isPrettierFile = async (f) => {
15
+ const fileInfo = await prettier.getFileInfo(f, {
16
+ ignorePath: ['.prettierignore', '.gitignore'],
17
+ resolveConfig: false,
18
+ });
19
+ return !fileInfo.ignored && fileInfo.inferredParser != null;
20
+ };
14
21
 
15
22
  /**
16
23
  * 检查文件是否是 eslint 支持的文件
@@ -80,14 +87,8 @@ module.exports = /** @type {import('lint-staged').Config} */ ({
80
87
  eslintFiles.push(file);
81
88
  } else if (isStylelintFile(file)) {
82
89
  stylelintFiles.push(file);
83
- } else {
84
- const filename = path.basename(file);
85
- if (
86
- prettierSupportedFilename.includes(filename) ||
87
- prettierSupportedExt.some((v) => filename.endsWith(v))
88
- ) {
89
- prettierFiles.push(file);
90
- }
90
+ } else if (await isPrettierFile(file)) {
91
+ prettierFiles.push(file);
91
92
  }
92
93
  }
93
94
 
package/package.json CHANGED
@@ -3,16 +3,16 @@
3
3
  "license": "MIT",
4
4
  "homepage": "https://cloudpss.net/",
5
5
  "repository": "https://codeup.aliyun.com/cloudpss/code-quality.git",
6
- "version": "1.4.4",
6
+ "version": "1.5.1",
7
7
  "main": "./index.js",
8
8
  "devDependencies": {
9
- "@types/eslint": "^8.40.2",
9
+ "@types/eslint": "^8.44.0",
10
10
  "@types/lint-staged": "^13.2.0",
11
11
  "@types/prettier": "^2.7.3"
12
12
  },
13
13
  "dependencies": {
14
- "eslint": "^8.43.0",
14
+ "eslint": "^8.44.0",
15
15
  "lint-staged": "^13.2.3",
16
- "prettier": "^2.8.8"
16
+ "prettier": "^3.0.0"
17
17
  }
18
18
  }