@secret-momo/toolchain-config 2.1.0 → 2.3.0
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 +78 -1
- package/eslint/files.mjs +6 -0
- package/eslint/imports.mjs +37 -0
- package/eslint/index.d.mts +14 -0
- package/eslint/index.mjs +21 -0
- package/eslint/languages.mjs +65 -0
- package/eslint/padding.mjs +44 -0
- package/eslint/style.mjs +58 -0
- package/package.json +30 -2
- package/prettier.config.mjs +6 -0
- package/stylelint.config.d.mts +5 -0
- package/stylelint.config.mjs +29 -0
package/README.md
CHANGED
|
@@ -1,6 +1,55 @@
|
|
|
1
1
|
# @secret-momo/toolchain-config
|
|
2
2
|
|
|
3
|
-
跨项目共享的 TypeScript 和
|
|
3
|
+
跨项目共享的 TypeScript、ESLint、Prettier 和 Stylelint 配置。需要 Node.js 26+,按需安装所用工具。
|
|
4
|
+
|
|
5
|
+
## ESLint 预设
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add -D @secret-momo/toolchain-config eslint@^10 typescript@~6.0.3
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
在项目根目录创建 `eslint.config.mjs`。ESLint 插件和 Prettier 兼容配置随共享包安装。需要格式化代码时,再按下文安装 Prettier。
|
|
12
|
+
|
|
13
|
+
```js
|
|
14
|
+
import createConfig from '@secret-momo/toolchain-config/eslint';
|
|
15
|
+
|
|
16
|
+
export default createConfig({ tsconfigRootDir: import.meta.dirname });
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
预设覆盖 `.js`、`.mjs`、`.cjs`、`.jsx`、`.ts`、`.tsx`、`.mts` 和 `.cts`,默认忽略各层级的 `dist/`、`build/` 和 `coverage/`。所有通用规则默认生效。
|
|
20
|
+
|
|
21
|
+
- 应用 ESLint 和 typescript-eslint 的推荐规则。TypeScript 使用内联类型导入,并检查弃用 API、未处理的 Promise 和用错 Promise 的场景。
|
|
22
|
+
- 自动移除未使用的导入,检查未使用变量。以下划线开头的变量、参数和捕获变量可保留。
|
|
23
|
+
- 导入按内置、外部、内部和相对路径分组,组间留空行。
|
|
24
|
+
- 配合 Prettier 保留控制结构的花括号、语法歧义检查和语义空行。在导入区块后、声明前后、多行代码块后、`return` 前及相邻类方法间检查空行,重载签名与实现可连续书写。
|
|
25
|
+
|
|
26
|
+
### 传入项目路径和文件范围
|
|
27
|
+
|
|
28
|
+
| 选项 | 用途 |
|
|
29
|
+
| ----------------------- | ------------------------------------------------------------------------ |
|
|
30
|
+
| `tsconfigRootDir` | 必填。项目根目录的绝对路径,配置在根目录时传 `import.meta.dirname`。 |
|
|
31
|
+
| `internalImportPattern` | 可选。用于识别内部导入的正则字符串,例如 `^(@/\|@workspace/)`。 |
|
|
32
|
+
| `browserFiles` | 可选。使用浏览器全局变量的文件 glob,默认所有源码使用 Node.js 全局变量。 |
|
|
33
|
+
|
|
34
|
+
每个受检 TypeScript 文件都需要归属一个 `tsconfig.json`。Monorepo 可以让各子包的 `tsconfig.json` 覆盖自己的源码。如果根目录 `.mts` 工具配置报出 `was not found by the project service`,请通过根 `tsconfig.json` 的 `include` 或项目引用把这些文件纳入检查。
|
|
35
|
+
|
|
36
|
+
下面的 monorepo 示例划定浏览器范围和内部导入前缀,并追加项目自己的忽略路径。React 等框架规则和业务约束也可以作为后续配置块叠加。
|
|
37
|
+
|
|
38
|
+
```js
|
|
39
|
+
import createConfig from '@secret-momo/toolchain-config/eslint';
|
|
40
|
+
import { defineConfig, globalIgnores } from 'eslint/config';
|
|
41
|
+
|
|
42
|
+
export default defineConfig(
|
|
43
|
+
globalIgnores(['packages/legacy/lib/']),
|
|
44
|
+
createConfig({
|
|
45
|
+
tsconfigRootDir: import.meta.dirname,
|
|
46
|
+
internalImportPattern: '^(@/|@workspace/)',
|
|
47
|
+
browserFiles: ['apps/web/src/**'],
|
|
48
|
+
}),
|
|
49
|
+
);
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
接入后运行 `pnpm exec eslint .`。已有项目可运行 `pnpm exec eslint . --fix`,自动整理导入、花括号和语义空行。
|
|
4
53
|
|
|
5
54
|
## Prettier 预设
|
|
6
55
|
|
|
@@ -28,6 +77,34 @@ import config from '@secret-momo/toolchain-config/prettier.config.mjs';
|
|
|
28
77
|
export default { ...config, printWidth: 100 };
|
|
29
78
|
```
|
|
30
79
|
|
|
80
|
+
## Stylelint 预设
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
pnpm add -D @secret-momo/toolchain-config stylelint@^18
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
在项目根目录创建 `stylelint.config.mjs`。标准预设及其所需的 Stylelint 版本随共享包安装,可以与项目已有的 Stylelint 版本共存。
|
|
87
|
+
|
|
88
|
+
```js
|
|
89
|
+
export default {
|
|
90
|
+
extends: ['@secret-momo/toolchain-config/stylelint'],
|
|
91
|
+
};
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
也可以直接导入预设,在本地补充设置。
|
|
95
|
+
|
|
96
|
+
```js
|
|
97
|
+
import config from '@secret-momo/toolchain-config/stylelint';
|
|
98
|
+
|
|
99
|
+
export default { ...config, ignoreFiles: ['**/dist/**'] };
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
普通 CSS 使用 `stylelint-config-standard`,类名采用 kebab-case。`*.module.css` 的选择器和 `@keyframes` 可使用 `:global()` 和 `:local()`。预设关闭模块的类名格式检查,并保留 `composes` 中类名的大小写。消费项目通过 `rules` 或 `overrides` 添加设计 token 等约束,并通过 lint 命令的 glob 或 `ignoreFiles` 指定检查范围。
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
pnpm exec stylelint 'src/**/*.css' --max-warnings=0
|
|
106
|
+
```
|
|
107
|
+
|
|
31
108
|
## TypeScript 预设
|
|
32
109
|
|
|
33
110
|
```bash
|
package/eslint/files.mjs
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
const javascriptExtensions = 'js,mjs,cjs,jsx';
|
|
2
|
+
const typescriptExtensions = 'ts,tsx,mts,cts';
|
|
3
|
+
|
|
4
|
+
export const javascriptFiles = `**/*.{${javascriptExtensions}}`;
|
|
5
|
+
export const typescriptFiles = `**/*.{${typescriptExtensions}}`;
|
|
6
|
+
export const sourceFiles = `**/*.{${javascriptExtensions},${typescriptExtensions}}`;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { defineConfig } from 'eslint/config';
|
|
2
|
+
import { importX } from 'eslint-plugin-import-x';
|
|
3
|
+
import unusedImports from 'eslint-plugin-unused-imports';
|
|
4
|
+
|
|
5
|
+
import { sourceFiles } from './files.mjs';
|
|
6
|
+
|
|
7
|
+
export function imports(internalImportPattern) {
|
|
8
|
+
return defineConfig({
|
|
9
|
+
name: 'toolchain/imports',
|
|
10
|
+
files: [sourceFiles],
|
|
11
|
+
plugins: { 'import-x': importX, 'unused-imports': unusedImports },
|
|
12
|
+
// 用消费项目的前缀识别工作区包和别名,避免导入分组依赖文件系统解析结果。
|
|
13
|
+
settings: internalImportPattern ? { 'import-x/internal-regex': internalImportPattern } : {},
|
|
14
|
+
rules: {
|
|
15
|
+
// 由 unused-imports 统一报告未使用项,并提供移除未使用导入的自动修复。
|
|
16
|
+
'no-unused-vars': 'off',
|
|
17
|
+
'@typescript-eslint/no-unused-vars': 'off',
|
|
18
|
+
'unused-imports/no-unused-imports': 'error',
|
|
19
|
+
'unused-imports/no-unused-vars': [
|
|
20
|
+
'error',
|
|
21
|
+
{
|
|
22
|
+
args: 'after-used',
|
|
23
|
+
argsIgnorePattern: '^_',
|
|
24
|
+
varsIgnorePattern: '^_',
|
|
25
|
+
caughtErrorsIgnorePattern: '^_',
|
|
26
|
+
},
|
|
27
|
+
],
|
|
28
|
+
'import-x/order': [
|
|
29
|
+
'error',
|
|
30
|
+
{
|
|
31
|
+
groups: ['builtin', 'external', 'internal', ['parent', 'sibling', 'index']],
|
|
32
|
+
'newlines-between': 'always',
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Config } from 'eslint/config';
|
|
2
|
+
|
|
3
|
+
interface Options {
|
|
4
|
+
/** 消费项目根目录的绝对路径,通常传入配置文件的 import.meta.dirname。 */
|
|
5
|
+
tsconfigRootDir: string;
|
|
6
|
+
/** 用于识别内部导入的正则字符串,例如 ^(@/|@workspace/)。 */
|
|
7
|
+
internalImportPattern?: string;
|
|
8
|
+
/** 使用浏览器全局变量的文件 glob,其余源码使用 Node.js 全局变量。 */
|
|
9
|
+
browserFiles?: string[];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
declare function createConfig(options: Options): Config[];
|
|
13
|
+
|
|
14
|
+
export default createConfig;
|
package/eslint/index.mjs
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { isAbsolute } from 'node:path';
|
|
2
|
+
|
|
3
|
+
import { defineConfig, globalIgnores } from 'eslint/config';
|
|
4
|
+
|
|
5
|
+
import { imports } from './imports.mjs';
|
|
6
|
+
import { environments, languages } from './languages.mjs';
|
|
7
|
+
import style from './style.mjs';
|
|
8
|
+
|
|
9
|
+
export default function createConfig({ tsconfigRootDir, internalImportPattern, browserFiles = [] } = {}) {
|
|
10
|
+
if (typeof tsconfigRootDir !== 'string' || !isAbsolute(tsconfigRootDir)) {
|
|
11
|
+
throw new TypeError('tsconfigRootDir 必须是消费项目的绝对路径,可传入 import.meta.dirname。');
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return defineConfig(
|
|
15
|
+
globalIgnores(['**/dist/', '**/build/', '**/coverage/'], 'toolchain/ignores'),
|
|
16
|
+
languages(tsconfigRootDir),
|
|
17
|
+
environments(browserFiles),
|
|
18
|
+
imports(internalImportPattern),
|
|
19
|
+
style,
|
|
20
|
+
);
|
|
21
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import js from '@eslint/js';
|
|
2
|
+
import { defineConfig } from 'eslint/config';
|
|
3
|
+
import globals from 'globals';
|
|
4
|
+
import tseslint from 'typescript-eslint';
|
|
5
|
+
|
|
6
|
+
import { javascriptFiles, sourceFiles, typescriptFiles } from './files.mjs';
|
|
7
|
+
|
|
8
|
+
export function languages(tsconfigRootDir) {
|
|
9
|
+
return defineConfig(
|
|
10
|
+
{
|
|
11
|
+
name: 'toolchain/javascript',
|
|
12
|
+
files: [javascriptFiles],
|
|
13
|
+
extends: [js.configs.recommended],
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
name: 'toolchain/jsx',
|
|
17
|
+
files: ['**/*.jsx'],
|
|
18
|
+
languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } },
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
name: 'toolchain/typescript',
|
|
22
|
+
files: [typescriptFiles],
|
|
23
|
+
extends: [js.configs.recommended, tseslint.configs.recommended],
|
|
24
|
+
languageOptions: {
|
|
25
|
+
parserOptions: {
|
|
26
|
+
// 由 TypeScript 项目服务按文件找到所属 tsconfig。根目录取自消费项目。
|
|
27
|
+
projectService: true,
|
|
28
|
+
tsconfigRootDir,
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
rules: {
|
|
32
|
+
'@typescript-eslint/consistent-type-imports': ['error', { fixStyle: 'inline-type-imports' }],
|
|
33
|
+
'@typescript-eslint/no-deprecated': 'error',
|
|
34
|
+
'@typescript-eslint/no-floating-promises': 'error',
|
|
35
|
+
'@typescript-eslint/no-misused-promises': 'error',
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
name: 'toolchain/typescript-commonjs',
|
|
40
|
+
files: ['**/*.cts'],
|
|
41
|
+
// TS 推荐配置默认使用 module。显式标记为 CommonJS 的扩展名保留自己的模块语义。
|
|
42
|
+
languageOptions: { sourceType: 'commonjs' },
|
|
43
|
+
},
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function environments(browserFiles) {
|
|
48
|
+
const configs = defineConfig({
|
|
49
|
+
name: 'toolchain/node-globals',
|
|
50
|
+
files: [sourceFiles],
|
|
51
|
+
ignores: browserFiles,
|
|
52
|
+
languageOptions: { globals: globals.node },
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
if (browserFiles.length > 0) {
|
|
56
|
+
configs.push({
|
|
57
|
+
name: 'toolchain/browser-globals',
|
|
58
|
+
// 取项目 glob 与源码扩展名的交集,确保宽泛的目录 glob 不会纳入其他文件类型。
|
|
59
|
+
files: browserFiles.map((pattern) => [sourceFiles, pattern]),
|
|
60
|
+
languageOptions: { globals: globals.browser },
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return configs;
|
|
65
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import stylistic from '@stylistic/eslint-plugin';
|
|
2
|
+
|
|
3
|
+
const padding = stylistic.rules['padding-line-between-statements'];
|
|
4
|
+
|
|
5
|
+
function followsOwnOverload(statement) {
|
|
6
|
+
const declaration = statement?.declaration ?? statement;
|
|
7
|
+
|
|
8
|
+
if (declaration?.type !== 'FunctionDeclaration' && declaration?.type !== 'TSDeclareFunction') {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const siblings = statement.parent?.body ?? statement.parent?.consequent;
|
|
13
|
+
|
|
14
|
+
if (!Array.isArray(siblings)) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const previous = siblings[siblings.indexOf(statement) - 1];
|
|
19
|
+
const signature = previous?.declaration ?? previous;
|
|
20
|
+
|
|
21
|
+
return (
|
|
22
|
+
signature?.type === 'TSDeclareFunction' &&
|
|
23
|
+
signature.id?.name === declaration.id?.name &&
|
|
24
|
+
(previous === signature ? statement === declaration : previous.type === statement.type)
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export default {
|
|
29
|
+
...padding,
|
|
30
|
+
create(context) {
|
|
31
|
+
// 由 Stylistic 检查空行并处理注释和自动修复。这里只豁免同一函数且导出形式一致的相邻重载。
|
|
32
|
+
return padding.create(
|
|
33
|
+
Object.create(context, {
|
|
34
|
+
report: {
|
|
35
|
+
value(report) {
|
|
36
|
+
if (report.messageId !== 'expectedBlankLine' || !followsOwnOverload(report.node)) {
|
|
37
|
+
context.report(report);
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
}),
|
|
42
|
+
);
|
|
43
|
+
},
|
|
44
|
+
};
|
package/eslint/style.mjs
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import stylistic from '@stylistic/eslint-plugin';
|
|
2
|
+
import { defineConfig } from 'eslint/config';
|
|
3
|
+
import prettier from 'eslint-config-prettier/flat';
|
|
4
|
+
|
|
5
|
+
import { sourceFiles } from './files.mjs';
|
|
6
|
+
import padding from './padding.mjs';
|
|
7
|
+
|
|
8
|
+
// 声明、带 export 的声明和使用变量绑定的函数都参与语义空行检查。
|
|
9
|
+
const declarationTypes = [
|
|
10
|
+
'FunctionDeclaration',
|
|
11
|
+
'ClassDeclaration',
|
|
12
|
+
'TSInterfaceDeclaration',
|
|
13
|
+
'TSTypeAliasDeclaration',
|
|
14
|
+
'TSEnumDeclaration',
|
|
15
|
+
'TSModuleDeclaration',
|
|
16
|
+
'TSDeclareFunction',
|
|
17
|
+
];
|
|
18
|
+
const variableFunction =
|
|
19
|
+
'VariableDeclaration > VariableDeclarator[init.type=/^(ArrowFunctionExpression|FunctionExpression)$/]';
|
|
20
|
+
const separatedDeclaration = {
|
|
21
|
+
selector: [
|
|
22
|
+
`:matches(${declarationTypes.join(', ')})`,
|
|
23
|
+
`:matches(ExportNamedDeclaration, ExportDefaultDeclaration)[declaration.type=/^(${declarationTypes.join('|')})$/]`,
|
|
24
|
+
`VariableDeclaration:has(${variableFunction})`,
|
|
25
|
+
`ExportNamedDeclaration[declaration.type="VariableDeclaration"]:has(${variableFunction})`,
|
|
26
|
+
].join(', '),
|
|
27
|
+
};
|
|
28
|
+
export default defineConfig(
|
|
29
|
+
{
|
|
30
|
+
name: 'toolchain/prettier-compatibility',
|
|
31
|
+
files: [sourceFiles],
|
|
32
|
+
extends: [prettier],
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
name: 'toolchain/style',
|
|
36
|
+
files: [sourceFiles],
|
|
37
|
+
plugins: { '@stylistic': stylistic, toolchain: { rules: { 'padding-line-between-statements': padding } } },
|
|
38
|
+
// 放在 Prettier 兼容层之后,保留控制结构花括号、语法歧义检查和语义空行。
|
|
39
|
+
rules: {
|
|
40
|
+
curly: ['error', 'all'],
|
|
41
|
+
'no-unexpected-multiline': 'error',
|
|
42
|
+
'toolchain/padding-line-between-statements': [
|
|
43
|
+
'error',
|
|
44
|
+
{ blankLine: 'always', prev: 'import', next: '*' },
|
|
45
|
+
{ blankLine: 'any', prev: 'import', next: 'import' },
|
|
46
|
+
{ blankLine: 'always', prev: '*', next: separatedDeclaration },
|
|
47
|
+
{ blankLine: 'always', prev: separatedDeclaration, next: '*' },
|
|
48
|
+
{ blankLine: 'always', prev: 'multiline-block-like', next: '*' },
|
|
49
|
+
{ blankLine: 'always', prev: '*', next: 'return' },
|
|
50
|
+
],
|
|
51
|
+
'@stylistic/lines-between-class-members': [
|
|
52
|
+
'error',
|
|
53
|
+
{ enforce: [{ blankLine: 'always', prev: 'method', next: 'method' }] },
|
|
54
|
+
{ exceptAfterOverload: true },
|
|
55
|
+
],
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@secret-momo/toolchain-config",
|
|
3
|
-
"version": "2.
|
|
4
|
-
"description": "跨项目共享的 TypeScript 和
|
|
3
|
+
"version": "2.3.0",
|
|
4
|
+
"description": "跨项目共享的 TypeScript、ESLint、Prettier 和 Stylelint 配置。",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
@@ -10,10 +10,18 @@
|
|
|
10
10
|
"directory": "packages/toolchain-config"
|
|
11
11
|
},
|
|
12
12
|
"exports": {
|
|
13
|
+
"./eslint": {
|
|
14
|
+
"types": "./eslint/index.d.mts",
|
|
15
|
+
"default": "./eslint/index.mjs"
|
|
16
|
+
},
|
|
13
17
|
"./prettier.config.mjs": {
|
|
14
18
|
"types": "./prettier.config.d.mts",
|
|
15
19
|
"default": "./prettier.config.mjs"
|
|
16
20
|
},
|
|
21
|
+
"./stylelint": {
|
|
22
|
+
"types": "./stylelint.config.d.mts",
|
|
23
|
+
"default": "./stylelint.config.mjs"
|
|
24
|
+
},
|
|
17
25
|
"./tsconfig/base.json": "./tsconfig/base.json",
|
|
18
26
|
"./tsconfig/node.json": "./tsconfig/node.json",
|
|
19
27
|
"./tsconfig/browser.json": "./tsconfig/browser.json",
|
|
@@ -28,8 +36,12 @@
|
|
|
28
36
|
"./tsconfig/declarations.json": "./tsconfig/declarations.json"
|
|
29
37
|
},
|
|
30
38
|
"files": [
|
|
39
|
+
"eslint/*.mjs",
|
|
40
|
+
"eslint/*.d.mts",
|
|
31
41
|
"prettier.config.mjs",
|
|
32
42
|
"prettier.config.d.mts",
|
|
43
|
+
"stylelint.config.mjs",
|
|
44
|
+
"stylelint.config.d.mts",
|
|
33
45
|
"tsconfig/**/*.json"
|
|
34
46
|
],
|
|
35
47
|
"engines": {
|
|
@@ -39,11 +51,27 @@
|
|
|
39
51
|
"access": "public",
|
|
40
52
|
"registry": "https://registry.npmjs.org/"
|
|
41
53
|
},
|
|
54
|
+
"dependencies": {
|
|
55
|
+
"@eslint/js": "10.0.1",
|
|
56
|
+
"@stylistic/eslint-plugin": "6.0.1",
|
|
57
|
+
"@typescript-eslint/eslint-plugin": "8.74.0",
|
|
58
|
+
"eslint-config-prettier": "10.1.8",
|
|
59
|
+
"eslint-plugin-import-x": "4.18.1",
|
|
60
|
+
"eslint-plugin-unused-imports": "4.4.1",
|
|
61
|
+
"globals": "17.14.0",
|
|
62
|
+
"stylelint": "18.1.0",
|
|
63
|
+
"stylelint-config-standard": "41.1.0",
|
|
64
|
+
"typescript-eslint": "8.74.0"
|
|
65
|
+
},
|
|
42
66
|
"peerDependencies": {
|
|
67
|
+
"eslint": "^10.0.0",
|
|
43
68
|
"prettier": "^3.0.0",
|
|
44
69
|
"typescript": "~6.0.3"
|
|
45
70
|
},
|
|
46
71
|
"peerDependenciesMeta": {
|
|
72
|
+
"eslint": {
|
|
73
|
+
"optional": true
|
|
74
|
+
},
|
|
47
75
|
"prettier": {
|
|
48
76
|
"optional": true
|
|
49
77
|
},
|
package/prettier.config.mjs
CHANGED
|
@@ -1,19 +1,25 @@
|
|
|
1
1
|
/** @type {import('prettier').Config} */
|
|
2
2
|
const config = {
|
|
3
|
+
// JS/TS 字符串优先用单引号,JSX 的字符串属性沿用 HTML 风格的双引号。
|
|
3
4
|
singleQuote: true,
|
|
4
5
|
jsxSingleQuote: false,
|
|
6
|
+
// 多行结构在语法允许时保留尾逗号,追加一项时可减少对上一行的改动。
|
|
5
7
|
trailingComma: 'all',
|
|
8
|
+
// 以 120 列作为折行目标,遇到难以拆分的内容时允许超出。
|
|
6
9
|
printWidth: 120,
|
|
7
10
|
overrides: [
|
|
8
11
|
{
|
|
9
12
|
files: ['*.md', '*.markdown'],
|
|
10
13
|
options: {
|
|
14
|
+
// 文档不受全局的 120 列约束,代码围栏中由 Prettier 格式化的示例也适用。
|
|
11
15
|
printWidth: Number.POSITIVE_INFINITY,
|
|
16
|
+
// 普通段落合并软换行,交由编辑器或阅读器按显示宽度折行。
|
|
12
17
|
proseWrap: 'never',
|
|
13
18
|
},
|
|
14
19
|
},
|
|
15
20
|
{
|
|
16
21
|
files: '*.jsonc',
|
|
22
|
+
// 去掉尾逗号,兼容默认拒绝尾逗号的 JSONC 解析器。
|
|
17
23
|
options: { trailingComma: 'none' },
|
|
18
24
|
},
|
|
19
25
|
],
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { fileURLToPath } from 'node:url';
|
|
2
|
+
|
|
3
|
+
/** @type {import('stylelint').Config} */
|
|
4
|
+
const config = {
|
|
5
|
+
// 让 ESM 导入的配置也从共享包解析标准预设。
|
|
6
|
+
extends: [fileURLToPath(import.meta.resolve('stylelint-config-standard'))],
|
|
7
|
+
overrides: [
|
|
8
|
+
{
|
|
9
|
+
files: ['**/*.module.css'],
|
|
10
|
+
languageOptions: {
|
|
11
|
+
syntax: {
|
|
12
|
+
atRules: {
|
|
13
|
+
keyframes: { prelude: '| :global( <custom-ident> ) | :local( <custom-ident> )' },
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
rules: {
|
|
18
|
+
'selector-class-pattern': null,
|
|
19
|
+
'selector-pseudo-class-no-unknown': [true, { ignorePseudoClasses: ['global', 'local'] }],
|
|
20
|
+
'property-no-unknown': [true, { ignoreProperties: ['composes'] }],
|
|
21
|
+
'value-keyword-case': ['lower', { ignoreProperties: ['composes'] }],
|
|
22
|
+
// 作用域内的名称由关键帧语法校验。普通关键帧名称沿用 kebab-case。
|
|
23
|
+
'keyframes-name-pattern': /^(?:[a-z][a-z0-9]*(?:-[a-z0-9]+)*|:(?:global|local)\([\s\S]+\))$/,
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export default config;
|