@zpcscc/configs 2.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 zpcscc
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,204 @@
1
+ # @zpcscc/configs
2
+
3
+ [![NPM version](https://img.shields.io/npm/v/@zpcscc/configs.svg?style=flat)](https://www.npmjs.com/package/@zpcscc/configs)
4
+ [![NPM downloads](http://img.shields.io/npm/dm/@zpcscc/configs.svg?style=flat)](https://www.npmjs.com/package/@zpcscc/configs)
5
+
6
+ # 简介
7
+
8
+ 通用配置库
9
+
10
+
11
+ ## 安装
12
+
13
+ ```sh
14
+ npm install --save-dev @zpcscc/configs
15
+ ```
16
+
17
+ ## 使用
18
+
19
+ ### eslint
20
+
21
+ `.eslintrc.js`
22
+
23
+ #### 基础配置
24
+
25
+ ```javascript
26
+ module.exports = {
27
+ extends: [require.resolve('@zpcscc/configs/eslint-config')],
28
+ };
29
+ ```
30
+
31
+ #### react的eslint配置
32
+
33
+ ```javascript
34
+ module.exports = {
35
+ extends: [require.resolve('@zpcscc/configs/eslint-config/react')],
36
+ };
37
+ ```
38
+
39
+ #### vue的eslint配置
40
+
41
+ ```javascript
42
+ module.exports = {
43
+ extends: [require.resolve('@zpcscc/configs/eslint-config/vue')],
44
+ };
45
+ ```
46
+
47
+ #### node的eslint配置
48
+
49
+ ```javascript
50
+ module.exports = {
51
+ extends: [require.resolve('@zpcscc/configs/eslint-config/node')],
52
+ };
53
+ ```
54
+
55
+ #### 补充配置
56
+
57
+ ```javascript
58
+ module.exports = {
59
+ // 由于使用了eslint-config-standard-with-typescript插件对ts的支持
60
+ // 部分规则需要tsconfig.json配置,需要在这里引入tsconfig.json文件
61
+ parserOptions: {
62
+ project: ['./tsconfig.json'],
63
+ },
64
+ };
65
+ ```
66
+
67
+ `tsconfig.json`
68
+
69
+ tsconfig.json 文件中,也需要在 include 中引入.eslintrc.js 文件
70
+
71
+ ```json
72
+ {
73
+ "include": [".eslintrc.js"]
74
+ }
75
+ ```
76
+
77
+
78
+
79
+ ### prettier
80
+
81
+ `.prettierrc`
82
+
83
+ ```js
84
+ '@zpcscc/configs/prettier-config';
85
+ ```
86
+
87
+ `.prettierrc.js`
88
+
89
+ ```js
90
+ module.exports = {
91
+ ...require('@zpcscc/configs/prettier-config'),
92
+ };
93
+ ```
94
+
95
+
96
+
97
+ ### stylelint
98
+
99
+ `.stylelintrc`
100
+
101
+ ```json
102
+ {
103
+ "extends": "@zpcscc/configs/stylelint-config"
104
+ }
105
+ ```
106
+
107
+ `stylelint.config.js`
108
+
109
+ ```js
110
+ module.exports = {
111
+ extends: ['@zpcscc/configs/stylelint-config'],
112
+ }
113
+ ```
114
+
115
+
116
+
117
+ ### tsconfig
118
+
119
+ `tsconfig.json`
120
+
121
+ #### 基础配置
122
+
123
+ ```json
124
+ {
125
+ "extends": "@zpcscc/configs/tsconfig/tsconfig.base.json",
126
+ }
127
+ ```
128
+
129
+ #### react的tsconfig配置
130
+
131
+ ```json
132
+ {
133
+ "extends": "@zpcscc/configs/tsconfig/tsconfig.react.json",
134
+ }
135
+ ```
136
+
137
+ #### vue的tsconfig配置
138
+
139
+ ```json
140
+ {
141
+ "extends": "@zpcscc/configs/tsconfig/tsconfig.vue.json",
142
+ }
143
+ ```
144
+
145
+ ### commitlint
146
+
147
+ `package.json`
148
+
149
+ ```json
150
+ "scripts": {
151
+ "commit": "git add . && git-cz",
152
+ },
153
+ ```
154
+
155
+ `.czrc`
156
+
157
+ ```json
158
+ {
159
+ "path": "@commitlint/cz-commitlint"
160
+ }
161
+ ```
162
+
163
+ `commitlint.config.js`
164
+
165
+ ```js
166
+ module.exports = {
167
+ extends: ['@zpcscc/configs/commitlint-config'],
168
+ };
169
+ ```
170
+
171
+ 上述文件设置好后,提交代码时使用下列命令
172
+
173
+ ```shell
174
+ npm run commit
175
+ ```
176
+
177
+ 若要默认使用`git cz`则需全局安装相关依赖
178
+
179
+ ```shell
180
+ npm i -g commitizen inquirer@8 @commitlint/cz-commitlint
181
+ ```
182
+
183
+
184
+
185
+ ### types
186
+
187
+ `types.d.ts`
188
+
189
+ ```bash
190
+ // 基础配置
191
+ /// <reference types="@zpcscc/configs/types" />
192
+ // react配置
193
+ /// <reference types="@zpcscc/configs/types/react" />
194
+ // vue配置
195
+ /// <reference types="@zpcscc/configs/types/vue" />
196
+ ```
197
+
198
+
199
+
200
+
201
+
202
+ ## License
203
+
204
+ MIT © [zpcscc](https://github.com/zpcscc)
@@ -0,0 +1,120 @@
1
+ // https://github.com/conventional-changelog/commitlint/tree/master/docs
2
+ module.exports = {
3
+ parserPreset: {
4
+ parserOpts: {
5
+ headerPattern: /^(.*)(?:\((.*)\))?!?: (.*)$/
6
+ }
7
+ },
8
+ rules: {
9
+ 'body-leading-blank': [1, 'always'],
10
+ 'body-max-line-length': [2, 'always', 100],
11
+ 'footer-leading-blank': [1, 'always'],
12
+ 'footer-max-line-length': [2, 'always', 100],
13
+ 'header-max-length': [2, 'always', 100],
14
+ 'subject-case': [2, 'never', ['sentence-case', 'start-case', 'pascal-case', 'upper-case']],
15
+ 'subject-empty': [2, 'never'],
16
+ 'subject-full-stop': [2, 'never', '.'],
17
+ 'type-case': [2, 'always', 'lower-case'],
18
+ 'type-empty': [2, 'never'],
19
+ 'type-enum': [2, 'always', ['✨feat', '🐛fix', '🔥update', '📚docs', '💎style', '📦refactor', '🚀perf', '🚨test', '🛠build', '⚙️ ci', '🗑revert']]
20
+ },
21
+ prompt: {
22
+ message: {
23
+ skip: '该字段可以通过回车跳过',
24
+ max: '最大字符数',
25
+ min: '最小字符数',
26
+ emptyWarning: '该字段不能为空',
27
+ upperLimitWarning: '超出字符数限制',
28
+ lowerLimitWarning: '字符小于下限'
29
+ },
30
+ questions: {
31
+ type: {
32
+ description: '选择当前 commit 的类型',
33
+ enum: {
34
+ '✨feat': {
35
+ description: '新功能',
36
+ title: '✨Features',
37
+ emoji: '✨'
38
+ },
39
+ '🔥update': {
40
+ description: '功能更新',
41
+ title: '🔥Update',
42
+ emoji: '🔥'
43
+ },
44
+ '🐛fix': {
45
+ description: '修复bug',
46
+ title: '🐛Bug Fixes',
47
+ emoji: '🐛'
48
+ },
49
+ '📚docs': {
50
+ description: '文档更新',
51
+ title: '📚Documentation',
52
+ emoji: '📚'
53
+ },
54
+ '💎style': {
55
+ description: '代码风格的更改(空格,逗号,缺少分号等)',
56
+ title: '💎Styles',
57
+ emoji: '💎'
58
+ },
59
+ '📦refactor': {
60
+ description: '代码重构(即不修复bug也不增加新功能)',
61
+ title: '📦Code Refactoring',
62
+ emoji: '📦'
63
+ },
64
+ '🚀perf': {
65
+ description: '性能提升',
66
+ title: '🚀Performance Improvements',
67
+ emoji: '🚀'
68
+ },
69
+ '🚨test': {
70
+ description: '添加测试文件或者更改测试文件',
71
+ title: '🚨Tests',
72
+ emoji: '🚨'
73
+ },
74
+ '🛠build': {
75
+ description: '构建系统或依赖更新,如webpack、rollup更改或者npm',
76
+ title: '🛠Builds',
77
+ emoji: '🛠'
78
+ },
79
+ '⚙️ ci': {
80
+ description: 'ci配置的更改,如 travis、github-ci',
81
+ title: '⚙️Continuous Integrations',
82
+ emoji: '⚙️'
83
+ },
84
+ '🗑revert': {
85
+ description: '恢复以前的提交(如git revert)',
86
+ title: '🗑Reverts',
87
+ emoji: '🗑'
88
+ }
89
+ }
90
+ },
91
+ scope: {
92
+ description: '变动访问,模块或者文件名'
93
+ },
94
+ subject: {
95
+ description: '写一个简短的描述'
96
+ },
97
+ body: {
98
+ description: '提供更改的详细说明'
99
+ },
100
+ isBreaking: {
101
+ description: '是否有破坏性更新?'
102
+ },
103
+ breakingBody: {
104
+ description: '破坏性变更的详细描述'
105
+ },
106
+ breaking: {
107
+ description: '破坏性变更的详细描述简短描述'
108
+ },
109
+ isIssueAffected: {
110
+ description: '此更改是否影响任何已知问题?'
111
+ },
112
+ issuesBody: {
113
+ description: '如果问题已解决,则提交需要一个主体。请输入提交本身的详细描述'
114
+ },
115
+ issues: {
116
+ description: '添加问题参考 (e.g. "fix #123", "re #123".)'
117
+ }
118
+ }
119
+ }
120
+ };
@@ -0,0 +1,248 @@
1
+ // 官方文档 https://eslint.org/
2
+ // @ts-check
3
+ /**
4
+ * @type {import("eslint").Linter.Config}
5
+ */
6
+ module.exports = {
7
+ extends: [
8
+ // eslint 的官方推荐配置
9
+ 'eslint:recommended',
10
+ // eslint的标准配置
11
+ 'standard',
12
+ // ts的标准支持
13
+ 'standard-with-typescript',
14
+ // 对eslint注释的提示
15
+ 'plugin:eslint-comments/recommended',
16
+ // ts推荐配置,做了一些兼容处理
17
+ 'plugin:@typescript-eslint/recommended',
18
+ // eslint-plugin-import---对import的导入进行检查
19
+ 'plugin:import/recommended',
20
+ // eslint-import-resolver-typescript---import校验对typescript的支持。是eslint-plugin-import插件的补充
21
+ 'plugin:import/typescript',
22
+ // unicorn的推荐配置
23
+ 'plugin:unicorn/recommended',
24
+ // 对promise的推荐配置
25
+ 'plugin:promise/recommended',
26
+ // sonarjs的推荐配置
27
+ 'plugin:sonarjs/recommended',
28
+ // eslint-plugin-prettier的推荐配置,需要放在最后一位,内部启用了eslint-plugin-prettier插件
29
+ // 用于关闭eslint中的所有格式化配置,全部在.prettierrc中进行格式化配置
30
+ 'plugin:prettier/recommended'],
31
+ // 如果要在rules中针对某个插件做具体配置,则需要在plugins里先引入对应插件
32
+ plugins: ['@typescript-eslint', 'sonarjs', 'unicorn', 'promise', 'import'],
33
+ parserOptions: {
34
+ ecmaVersion: 'latest'
35
+ },
36
+ // 运行的环境
37
+ env: {
38
+ browser: true,
39
+ commonjs: true,
40
+ es2024: true,
41
+ node: true,
42
+ jest: true
43
+ },
44
+ settings: {
45
+ // eslint-import-resolver-typescript
46
+ 'import/resolver': {
47
+ typescript: true,
48
+ node: true
49
+ }
50
+ },
51
+ rules: {
52
+ // 数组类型。这里不限制写法
53
+ '@typescript-eslint/array-type': 'off',
54
+ // 限制命名规则。这里关闭。命名希望灵活些
55
+ '@typescript-eslint/naming-convention': 'off',
56
+ // 限制模板表达式。关闭此校验,希望模板表达式更加灵活
57
+ '@typescript-eslint/restrict-template-expressions': 'off',
58
+ // ts不允许有any类型。关闭此校验,特殊情况,需要any类型
59
+ '@typescript-eslint/no-explicit-any': 'off',
60
+ // 显示函数返回类型。关闭此校验,部分函数没有返回值。无需每个都显示类型
61
+ '@typescript-eslint/explicit-function-return-type': 'off',
62
+ // 严格的逻辑表达式。关闭此选项,可以使用 !value 的方式来进行判断;
63
+ '@typescript-eslint/strict-boolean-expressions': 'off',
64
+ // 为了安全使用 ?? 替换 ||。关闭此选项,部分场景,需要手动选择??还是||; ??会把空字符串也认为是true
65
+ '@typescript-eslint/prefer-nullish-coalescing': 'off',
66
+ // 无混淆空表达式。默认所有void都不能直接返回,需要用{}包裹。这里排除掉箭头函数。
67
+ // 可以直接写成 onchange={(value)=> onChange(value) }
68
+ // 而不是 onchange={(value)=>{ onChange(value) }}
69
+ '@typescript-eslint/no-confusing-void-expression': ['warn', {
70
+ ignoreArrowShorthand: true
71
+ }],
72
+ // import 类型时,需要加 type
73
+ '@typescript-eslint/consistent-type-imports': 'warn',
74
+ // 禁止变量重新声明
75
+ '@typescript-eslint/no-redeclare': 'warn',
76
+ // 无浮动的promise,要求处理每个promise的then和catch。
77
+ '@typescript-eslint/no-floating-promises': 'off',
78
+ // 强制使用一致性类型断言。<>语法,或者as语法
79
+ '@typescript-eslint/consistent-type-assertions': 'off',
80
+ // 不得滥用promise,这里关闭
81
+ '@typescript-eslint/no-misused-promises': 'off',
82
+ // 限制 + 操作符,两边必须相同。这里关闭
83
+ '@typescript-eslint/restrict-plus-operands': 'off',
84
+ // 禁止未使用的表达式
85
+ 'no-unused-expressions': 'off',
86
+ '@typescript-eslint/no-unused-expressions': ['error', {
87
+ allowShortCircuit: true,
88
+ allowTernary: true
89
+ }],
90
+ 'no-return-await': 'off',
91
+ // 若函数是async,则返回值需要有await
92
+ '@typescript-eslint/return-await': ['error'],
93
+ // promise函数都需要使用async。这里关闭。
94
+ '@typescript-eslint/promise-function-async': 'off',
95
+ // 禁止某些支持 ES6 样式导入声明的三重斜杠指令
96
+ '@typescript-eslint/triple-slash-reference': 'off',
97
+ // 函数体周围是否强制使用大括号。这里关闭,不强制。部分小函数,单行可以实现时,无需大括号限制
98
+ 'arrow-body-style': 'off',
99
+ // if语句是否需要加括号。设置为多行加括号,单行不需要加括号
100
+ curly: ['error', 'multi-line'],
101
+ 'default-param-last': 'off',
102
+ // 禁止速记类型转换
103
+ 'no-implicit-coercion': ['error'],
104
+ // 禁止console输入。这里关闭
105
+ 'no-console': 'off',
106
+ // 禁止使用continue跳出循环。这里关闭
107
+ 'no-continue': 'off',
108
+ // 使用更具有描述性的名称。这里关闭
109
+ 'unicorn/prevent-abbreviations': 'off',
110
+ // 不允许使用 array的reduce方法。这里关闭
111
+ 'unicorn/no-array-reduce': 'off',
112
+ // 不允许使用 new Array()声明数组。这里关闭
113
+ 'unicorn/no-new-array': 'off',
114
+ // 不允许使用 新的特性。这里关闭
115
+ 'unicorn/new-for-builtins': 'off',
116
+ // 不允许使用 array的forEach。这里管理
117
+ 'unicorn/no-array-for-each': 'off',
118
+ // 在属性上使用析构函数变量。这里关闭
119
+ 'unicorn/consistent-destructuring': 'off',
120
+ // 使用esm的格式,而不是commonjs。这里关闭。部分模块还是需要使用commonjs保证兼容性
121
+ 'unicorn/prefer-module': 'off',
122
+ // 箭头函数移动到外部作用于。这里关闭。在react组件内,经常会使用到箭头函数
123
+ 'unicorn/consistent-function-scoping': 'off',
124
+ // 禁止将函数直接传给方法。这里关闭。
125
+ 'unicorn/no-array-callback-reference': 'off',
126
+ // 不使用 null。这里关闭。实际上,与后台交互时,经常需要用到null。也更有语义化。
127
+ 'unicorn/no-null': 'off',
128
+ // 强制使用数字分隔符。这里关闭。
129
+ 'unicorn/numeric-separators-style': 'off',
130
+ // 名称校验,这里关闭
131
+ 'import/named': 'off',
132
+ // 禁止整个文件的注释,只允许注释文件块。这里关闭。
133
+ 'eslint-comments/disable-enable-pair': 'off',
134
+ // 函数名称后需要跟一个空格。这里关闭
135
+ 'space-before-function-paren': 'off',
136
+ // 返回值必须被使用。这里关闭
137
+ 'sonarjs/no-ignored-return': 'off',
138
+ // 以下配置待整理完善,以上配置已整理,尽量不要动了。
139
+ 'array-bracket-spacing': ['error', 'never'],
140
+ 'arrow-parens': ['error', 'always'],
141
+ 'arrow-spacing': ['error', {
142
+ after: true,
143
+ before: true
144
+ }],
145
+ camelcase: 'off',
146
+ 'consistent-return': 'off',
147
+ 'class-methods-use-this': 'off',
148
+ 'default-case-last': ['error'],
149
+ 'eol-last': ['error'],
150
+ eqeqeq: ['error', 'always', {
151
+ null: 'ignore'
152
+ }],
153
+ 'func-names': ['warn', 'never', {
154
+ generators: 'as-needed'
155
+ }],
156
+ 'func-style': ['error'],
157
+ 'import/export': 'off',
158
+ 'import/extensions': 'off',
159
+ 'import/no-cycle': 'off',
160
+ 'import/no-extraneous-dependencies': 'off',
161
+ 'import/no-named-as-default': 'off',
162
+ 'import/no-relative-packages': 'off',
163
+ 'import/no-unresolved': 'off',
164
+ 'import/prefer-default-export': 'off',
165
+ 'keyword-spacing': ['error'],
166
+ 'lines-between-class-members': 'off',
167
+ 'max-classes-per-file': 'off',
168
+ 'max-len': ['error', {
169
+ code: 180,
170
+ ignoreComments: true,
171
+ ignoreRegExpLiterals: true
172
+ }],
173
+ 'no-bitwise': ['error'],
174
+ 'no-class-assign': ['error'],
175
+ 'no-cond-assign': ['error', 'except-parens'],
176
+ 'no-const-assign': ['error'],
177
+ 'no-constructor-return': ['error'],
178
+ 'no-dupe-class-members': ['error'],
179
+ 'no-duplicate-imports': ['error'],
180
+ 'no-else-return': ['error'],
181
+ 'no-eval': ['error'],
182
+ 'no-inner-declarations': 'off',
183
+ 'no-labels': ['error'],
184
+ 'no-lonely-if': ['error'],
185
+ 'no-new': ['error'],
186
+ 'no-promise-executor-return': ['error'],
187
+ 'no-param-reassign': ['error', {
188
+ props: false
189
+ }],
190
+ 'no-plusplus': 'off',
191
+ 'no-return-assign': ['error', 'except-parens'],
192
+ 'no-shadow': 'off',
193
+ 'no-mixed-spaces-and-tabs': ['error'],
194
+ 'no-multi-assign': 'off',
195
+ 'no-multiple-empty-lines': ['error'],
196
+ 'no-nested-ternary': 'off',
197
+ 'no-new-symbol': ['error'],
198
+ 'no-spaced-func': ['error'],
199
+ 'no-trailing-spaces': ['error'],
200
+ 'no-use-before-define': 'off',
201
+ 'no-useless-computed-key': ['error'],
202
+ 'no-useless-concat': ['error'],
203
+ 'no-useless-constructor': 'off',
204
+ 'no-useless-return': ['error'],
205
+ 'no-useless-rename': ['error'],
206
+ 'no-undef': ['error'],
207
+ 'no-unexpected-multiline': ['error'],
208
+ 'no-unreachable-loop': ['error'],
209
+ 'no-unneeded-ternary': ['error'],
210
+ 'no-unused-vars': ['error', {
211
+ args: 'none',
212
+ vars: 'all'
213
+ }],
214
+ 'no-var': ['error'],
215
+ 'no-void': ['error'],
216
+ 'object-shorthand': ['error', 'always', {
217
+ avoidQuotes: true,
218
+ ignoreConstructors: false
219
+ }],
220
+ 'prefer-arrow-callback': ['error', {
221
+ allowNamedFunctions: false,
222
+ allowUnboundThis: true
223
+ }],
224
+ 'prefer-const': ['error'],
225
+ 'prefer-destructuring': 'off',
226
+ 'prefer-rest-params': ['error'],
227
+ 'prefer-template': ['error'],
228
+ 'promise/always-return': 'off',
229
+ 'promise/catch-or-return': 'off',
230
+ quotes: ['error'],
231
+ 'require-atomic-updates': ['error'],
232
+ semi: ['error', 'always'],
233
+ 'sonarjs/cognitive-complexity': 'off',
234
+ 'sonarjs/no-nested-template-literals': 'off',
235
+ 'sonarjs/no-duplicate-string': 'off',
236
+ 'sonarjs/no-small-switch': 'off',
237
+ 'sonarjs/prefer-immediate-return': 'off',
238
+ 'space-before-blocks': ['error', 'always'],
239
+ 'space-in-parens': ['error', 'never'],
240
+ 'space-unary-ops': ['error', {
241
+ nonwords: false,
242
+ overrides: {}
243
+ }],
244
+ 'symbol-description': ['error'],
245
+ 'template-curly-spacing': ['error', 'never'],
246
+ 'unicorn/filename-case': 'off'
247
+ }
248
+ };
@@ -0,0 +1,11 @@
1
+ // 官方文档 https://eslint.org/
2
+
3
+ // @ts-check
4
+ /**
5
+ * @type {import("eslint").Linter.Config}
6
+ */
7
+ module.exports = {
8
+ extends: [
9
+ // 对node的提示
10
+ 'plugin:n/recommended', require.resolve("../index")]
11
+ };
@@ -0,0 +1,55 @@
1
+ // @ts-check
2
+ /**
3
+ * @type {import("eslint").Linter.Config}
4
+ */
5
+ module.exports = {
6
+ extends: [
7
+ // 对react的推荐配置
8
+ 'plugin:react/recommended',
9
+ // react17及以上,新的jsx转换规则,需要引入react/jsx-runtime以禁止部分规则
10
+ 'plugin:react/jsx-runtime',
11
+ // react-hook的推荐配置
12
+ 'plugin:react-hooks/recommended',
13
+ // 对jsx的支持与推荐配置
14
+ 'plugin:jsx-a11y/recommended', require.resolve("../index")],
15
+ plugins: ['react', 'react-hooks'],
16
+ // 使用typescript解析器
17
+ parser: '@typescript-eslint/parser',
18
+ parserOptions: {
19
+ // 使用额外的语言特性
20
+ ecmaFeatures: {
21
+ // 开启jsx支持
22
+ jsx: true,
23
+ sourceType: 'module'
24
+ }
25
+ },
26
+ settings: {
27
+ // eslint-plugin-react的配置https://github.com/jsx-eslint/eslint-plugin-react#configuration
28
+ react: {
29
+ version: 'detect'
30
+ }
31
+ },
32
+ rules: {
33
+ 'react/destructuring-assignment': 'off',
34
+ // react17之后引入新的jsx转换。不再需要显示引入react。这两项规则需要关闭。
35
+ 'react/jsx-uses-react': 'off',
36
+ 'react/jsx-props-no-spreading': 'off',
37
+ // props类型检查.关闭此校验,ts有静态类型检查
38
+ 'react/prop-types': 'off',
39
+ 'react/react-in-jsx-scope': 'off',
40
+ 'react/self-closing-comp': 'warn',
41
+ 'react/sort-comp': 'off',
42
+ 'react/no-access-state-in-setstate': 'off',
43
+ // 禁止未知属性。这里忽略emotion里的css属性报错。将css属性视为正常属性
44
+ 'react/no-unknown-property': ['error', {
45
+ ignore: ['css']
46
+ }],
47
+ // useEffect数组的提示
48
+ 'react-hooks/exhaustive-deps': 'off',
49
+ // 非button的元素点击事件必须同时有个键盘事件。这里关闭
50
+ 'jsx-a11y/click-events-have-key-events': 'off',
51
+ // 交互式元素应是可聚焦的。这里关闭
52
+ 'jsx-a11y/interactive-supports-focus': 'off'
53
+ // 强制填写了默认值的参数在最后。需关闭此选项,否则部分函数参数值,无法任意调整位置。
54
+ }
55
+ };
@@ -0,0 +1,16 @@
1
+ // 官方文档 https://eslint.org/
2
+ /* eslint-env node */
3
+ require('@rushstack/eslint-patch/modern-module-resolution');
4
+
5
+ // @ts-check
6
+ /**
7
+ * @type {import("eslint").Linter.Config}
8
+ */
9
+ module.exports = {
10
+ extends: ['plugin:vue/vue3-recommended', '@vue/eslint-config-typescript', '@vue/eslint-config-prettier', require.resolve("../index")],
11
+ parser: 'vue-eslint-parser',
12
+ parserOptions: {
13
+ parser: '@typescript-eslint/parser',
14
+ sourceType: 'module'
15
+ }
16
+ };
package/package.json ADDED
@@ -0,0 +1,103 @@
1
+ {
2
+ "name": "@zpcscc/configs",
3
+ "version": "2.0.0",
4
+ "description": "项目通用配置",
5
+ "keywords": [
6
+ "commitlint",
7
+ "eslint",
8
+ "prettier",
9
+ "stylelint",
10
+ "tsconfig",
11
+ "types",
12
+ "react",
13
+ "vue",
14
+ "configs"
15
+ ],
16
+ "homepage": "https://zpcscc.github.io/configs",
17
+ "repository": "https://github.com/zpcscc/configs",
18
+ "license": "MIT",
19
+ "author": {
20
+ "name": "zpcscc",
21
+ "email": "dxsixpc@gmail.com"
22
+ },
23
+ "files": [
24
+ "dist",
25
+ "commitlint-config",
26
+ "eslint-config",
27
+ "prettier-config",
28
+ "stylelint-config",
29
+ "tsconfig",
30
+ "types"
31
+ ],
32
+ "scripts": {
33
+ "build": "father build",
34
+ "build:watch": "father dev",
35
+ "commit": "git add . && git-cz",
36
+ "deploy": "pnpm run docs:build && pnpm run docs:deploy",
37
+ "dev": "dumi dev",
38
+ "docs:build": "dumi build",
39
+ "docs:deploy": "gh-pages -d docs-dist",
40
+ "doctor": "father doctor",
41
+ "prepublishOnly": "father doctor && pnpm run build && cp -r ./dist/* . && rm -rf dist",
42
+ "postpublish": "git clean -fd",
43
+ "start": "dumi dev"
44
+ },
45
+ "dependencies": {
46
+ "@babel/core": "^7.23.2",
47
+ "@babel/plugin-syntax-flow": "^7.22.5",
48
+ "@babel/plugin-transform-react-jsx": "^7.22.15",
49
+ "@babel/runtime": "^7.23.2",
50
+ "@commitlint/cz-commitlint": "^18.2.0",
51
+ "@rushstack/eslint-patch": "^1.5.1",
52
+ "@types/node": "^20.8.10",
53
+ "@types/react": "^18.2.34",
54
+ "@types/react-dom": "^18.2.14",
55
+ "@typescript-eslint/eslint-plugin": "^6.9.1",
56
+ "@typescript-eslint/parser": "^6.9.1",
57
+ "@vue/eslint-config-prettier": "^8.0.0",
58
+ "@vue/eslint-config-typescript": "^12.0.0",
59
+ "commitizen": "^4.0.3",
60
+ "cosmiconfig": "^8.3.6",
61
+ "eslint": "^8.52.0",
62
+ "eslint-config-prettier": "^9.0.0",
63
+ "eslint-config-standard": "^17.1.0",
64
+ "eslint-config-standard-with-typescript": "^39.1.1",
65
+ "eslint-import-resolver-typescript": "^3.6.1",
66
+ "eslint-plugin-eslint-comments": "^3.2.0",
67
+ "eslint-plugin-import": "^2.29.0",
68
+ "eslint-plugin-jsx-a11y": "^6.8.0",
69
+ "eslint-plugin-n": "^16.2.0",
70
+ "eslint-plugin-prettier": "^5.0.1",
71
+ "eslint-plugin-promise": "^6.1.1",
72
+ "eslint-plugin-react": "^7.33.2",
73
+ "eslint-plugin-react-hooks": "^4.6.0",
74
+ "eslint-plugin-sonarjs": "^0.22.0",
75
+ "eslint-plugin-unicorn": "^49.0.0",
76
+ "eslint-plugin-vue": "^9.18.1",
77
+ "inquirer": "^8.2.5",
78
+ "postcss": "^8.4.31",
79
+ "prettier": "^3.0.3",
80
+ "prettier-plugin-organize-imports": "^3.2.3",
81
+ "prettier-plugin-packagejson": "^2.4.6",
82
+ "stylelint": "^14.16.1",
83
+ "stylelint-config-idiomatic-order": "^9.0.0",
84
+ "stylelint-declaration-block-no-ignored-properties": "^2.7.0",
85
+ "vue-eslint-parser": "^9.3.2"
86
+ },
87
+ "devDependencies": {
88
+ "dumi": "^2.2.14",
89
+ "father": "^4.3.6",
90
+ "gh-pages": "^6.0.0",
91
+ "react": "^18.2.0",
92
+ "react-dom": "^18.2.0",
93
+ "react-is": "^18.2.0",
94
+ "styled-components": "^6.1.0",
95
+ "tslib": "^2.6.2",
96
+ "typescript": "^5.2.2",
97
+ "webpack": "^5.89.0"
98
+ },
99
+ "publishConfig": {
100
+ "access": "public",
101
+ "registry": "https://registry.npmjs.org"
102
+ }
103
+ }
@@ -0,0 +1,71 @@
1
+ // 官方文档 https://prettier.io/
2
+ module.exports = {
3
+ // 额外的插件
4
+ plugins: [
5
+ // import格式化时自动排序
6
+ require.resolve('prettier-plugin-organize-imports'),
7
+ // package.json格式化时自动排序
8
+ require.resolve('prettier-plugin-packagejson')],
9
+ // import格式化自动排序时,不删除未使用的import
10
+ organizeImportsSkipDestructiveCodeActions: true,
11
+ // 结尾需要分号
12
+ semi: true,
13
+ // 使用单引号
14
+ singleQuote: true,
15
+ // 每行最大字符数量
16
+ printWidth: 100,
17
+ // 结尾逗号, 这里关闭,暂时不需要逗号
18
+ trailingComma: 'none',
19
+ // 每个缩进级别的空格数
20
+ tabWidth: 2,
21
+ // 是否使用制表符缩进
22
+ useTabs: false,
23
+ // 是否换行
24
+ proseWrap: 'never',
25
+ // 换行符,linux和macos中为'lf',window中为'crlf'
26
+ endOfLine: 'lf',
27
+ // 在jsx中是否使用单引号
28
+ jsxSingleQuote: true,
29
+ // 对象和括号之间是否需要空格
30
+ bracketSpacing: true,
31
+ // 将多行html标签放在最后一行末尾。而不是重开一行。这里关闭,希望重开一行。
32
+ bracketSameLine: false,
33
+ // 箭头函数,只有一个参数的时候,也需要括号
34
+ arrowParens: 'always',
35
+ // 对象的 key 仅在必要时用引号
36
+ quoteProps: 'as-needed',
37
+ // 不需要写文件开头的 @prettier
38
+ requirePragma: false,
39
+ // 不需要自动在文件开头插入 @prettier
40
+ insertPragma: false,
41
+ // 根据显示样式决定 html 要不要折行, 默认css
42
+ htmlWhitespaceSensitivity: 'css',
43
+ // vue 文件中的 script 和 style 内不用缩进
44
+ vueIndentScriptAndStyle: false,
45
+ // 格式化嵌入的内容
46
+ embeddedLanguageFormatting: 'auto',
47
+ // html, vue, jsx 中每个属性占一行
48
+ singleAttributePerLine: false,
49
+ // 重写部分文件的规则
50
+ overrides: [{
51
+ files: ['.eslintrc', '.prettierrc', '.stylelintrc'],
52
+ options: {
53
+ parser: 'json'
54
+ }
55
+ }, {
56
+ files: 'package*.json',
57
+ options: {
58
+ printWidth: 1000
59
+ }
60
+ }, {
61
+ files: '*.yml',
62
+ options: {
63
+ singleQuote: false
64
+ }
65
+ }, {
66
+ files: '*.md',
67
+ options: {
68
+ proseWrap: 'preserve'
69
+ }
70
+ }]
71
+ };
@@ -0,0 +1,43 @@
1
+ // 官方文档 https://stylelint.io/
2
+ module.exports = {
3
+ extends: [
4
+ // 标准配置
5
+ 'stylelint-config-standard',
6
+ // 惯用样式排序规则
7
+ 'stylelint-config-idiomatic-order'],
8
+ plugins: [
9
+ // 避免属性冲突而忽略某些属性
10
+ 'stylelint-declaration-block-no-ignored-properties'],
11
+ rules: {
12
+ // 缩进采用 2 个空格
13
+ indentation: 2,
14
+ // 声明中不允许出现“unknown”属性
15
+ 'declaration-property-value-no-unknown': true,
16
+ // 不能为空css样式块
17
+ 'block-no-empty': true,
18
+ // 指定css函数名为小写
19
+ 'function-name-case': 'lower',
20
+ // 禁止低权重选择权出现在高权重选择器之后
21
+ 'no-descending-specificity': true,
22
+ // 不允许重复选择器
23
+ 'no-duplicate-selectors': true,
24
+ // 统一使用双引号
25
+ 'string-quotes': 'double',
26
+ // 禁止使用!important
27
+ 'declaration-no-important': true,
28
+ // 指定每行最大长度
29
+ 'max-line-length': 80,
30
+ // 关键字大小写
31
+ 'value-keyword-case': null,
32
+ // 指定类选择器的模式。
33
+ 'selector-class-pattern': null,
34
+ // 指定关键帧名称的模式。
35
+ 'keyframes-name-pattern': null,
36
+ // 声明前是否需要空行
37
+ 'declaration-empty-line-before': null,
38
+ // 注释前是否需要空行
39
+ 'comment-empty-line-before': null,
40
+ // 不允许出现用双斜杠注释掉的样式
41
+ 'no-invalid-double-slash-comments': null
42
+ }
43
+ };
@@ -0,0 +1,50 @@
1
+ // 官方文档 https://www.typescriptlang.org/tsconfig
2
+ {
3
+ // 从外部引用的基础配置
4
+ "compilerOptions": {
5
+ // 启用后,会开启ts所有的严格检查,可在下方单独某项进行关闭;
6
+ "strict": true,
7
+ // 启用后,TypeScript 将检查函数中的所有代码路径以确保它们返回值;
8
+ "noImplicitReturns": true,
9
+ // 启用后,不允许使用any;
10
+ "noImplicitAny": false,
11
+ // 设置项目的模块类型
12
+ "module": "ESNext",
13
+ // 指定模块的解析策略.
14
+ "moduleResolution": "Node",
15
+ // 指定编译后的版本。编译后的代码需要在什么版本的环境下运行
16
+ "target": "ESNext",
17
+ // 提供全局的ts类型api
18
+ "lib": ["DOM", "DOM.Iterable", "ESNext"],
19
+ // 模块导入修复。启用此项会自动启用 allowSyntheticDefaultImports
20
+ "esModuleInterop": true,
21
+ // 为你工程中的每个 TypeScript 或 JavaScript 文件生成 .d.ts 文件。
22
+ "declaration": true,
23
+ // 跳过声明文件的类型检查
24
+ "skipLibCheck": true,
25
+ // 解析json模块,允许导入带有“.json”扩展名的模块
26
+ "resolveJsonModule": true,
27
+ // 只发出.d.ts文件;不发出.js文件。仅用作导出ts类型时开启;
28
+ "emitDeclarationOnly": false,
29
+ // 在文件名中强制使用一致的大小写
30
+ "forceConsistentCasingInFileNames": true,
31
+ // 启用生成 sourcemap files;这些文件允许调试器和其他工具在使用实际生成的 JavaScript 文件时,显示原始的 TypeScript 代码。
32
+ "sourceMap": true,
33
+ // 报告未使用的局部变量的错误。建议开启
34
+ "noUnusedLocals": true,
35
+ // 严格的空检查;建议开启,方便提示某字段可能为null,undefined,false等情况
36
+ "strictNullChecks": true,
37
+ // 启用对装饰器的实验性支持
38
+ "experimentalDecorators": true,
39
+ // 允许默认全部导出,而不是 * as newName的形式
40
+ "allowSyntheticDefaultImports": true,
41
+ // 开启后,所有的文件都应是模块
42
+ "isolatedModules": false
43
+ // 模块导入修复。启用此项会自动启用 allowSyntheticDefaultImports // ts 5.0后才支持。
44
+ // "verbatimModuleSyntax": true
45
+ // 允许在项目中导入js文件
46
+ // "allowJs": true,
47
+ // 为js文件提供类型检查,与allowJs配合使用。开启后,需要同时配置 outDir
48
+ // "checkJs": true,
49
+ }
50
+ }
@@ -0,0 +1,9 @@
1
+ // 官方文档 https://www.typescriptlang.org/tsconfig
2
+ {
3
+ "extends": "./tsconfig.base.json",
4
+ // 从外部引用的基础配置
5
+ "compilerOptions": {
6
+ // 控制 JSX 在 JavaScript 文件中的输出方式。 这只影响 .tsx 文件的 JS 文件输出;
7
+ "jsx": "react-jsx"
8
+ }
9
+ }
@@ -0,0 +1,13 @@
1
+ // 官方文档 https://www.typescriptlang.org/tsconfig
2
+ {
3
+ "extends": "./tsconfig.base.json",
4
+ "compilerOptions": {
5
+ "useDefineForClassFields": true,
6
+ // vue 项目中,必须是preserve
7
+ "jsx": "preserve",
8
+ // 没有隐含的this。防止this指向错误
9
+ "noImplicitThis": true,
10
+ // Vite项目中必须开启
11
+ "isolatedModules": true
12
+ }
13
+ }
@@ -0,0 +1,240 @@
1
+ // 一些文件类型
2
+
3
+ // CSS modules
4
+ type CSSModuleClasses = Readonly<Record<string, string>>;
5
+
6
+ declare module '*.module.css' {
7
+ const classes: CSSModuleClasses;
8
+ export default classes;
9
+ }
10
+ declare module '*.module.scss' {
11
+ const classes: CSSModuleClasses;
12
+ export default classes;
13
+ }
14
+ declare module '*.module.sass' {
15
+ const classes: CSSModuleClasses;
16
+ export default classes;
17
+ }
18
+ declare module '*.module.less' {
19
+ const classes: CSSModuleClasses;
20
+ export default classes;
21
+ }
22
+ declare module '*.module.styl' {
23
+ const classes: CSSModuleClasses;
24
+ export default classes;
25
+ }
26
+ declare module '*.module.stylus' {
27
+ const classes: CSSModuleClasses;
28
+ export default classes;
29
+ }
30
+ declare module '*.module.pcss' {
31
+ const classes: CSSModuleClasses;
32
+ export default classes;
33
+ }
34
+ declare module '*.module.sss' {
35
+ const classes: CSSModuleClasses;
36
+ export default classes;
37
+ }
38
+
39
+ // CSS
40
+ declare module '*.css' {
41
+ const css: string;
42
+ export default css;
43
+ }
44
+ declare module '*.scss' {
45
+ const css: string;
46
+ export default css;
47
+ }
48
+ declare module '*.sass' {
49
+ const css: string;
50
+ export default css;
51
+ }
52
+ declare module '*.less' {
53
+ const css: string;
54
+ export default css;
55
+ }
56
+ declare module '*.styl' {
57
+ const css: string;
58
+ export default css;
59
+ }
60
+ declare module '*.stylus' {
61
+ const css: string;
62
+ export default css;
63
+ }
64
+ declare module '*.pcss' {
65
+ const css: string;
66
+ export default css;
67
+ }
68
+ declare module '*.sss' {
69
+ const css: string;
70
+ export default css;
71
+ }
72
+
73
+ // images
74
+ declare module '*.png' {
75
+ const src: string;
76
+ export default src;
77
+ }
78
+ declare module '*.jpg' {
79
+ const src: string;
80
+ export default src;
81
+ }
82
+ declare module '*.jpeg' {
83
+ const src: string;
84
+ export default src;
85
+ }
86
+ declare module '*.jfif' {
87
+ const src: string;
88
+ export default src;
89
+ }
90
+ declare module '*.pjpeg' {
91
+ const src: string;
92
+ export default src;
93
+ }
94
+ declare module '*.pjp' {
95
+ const src: string;
96
+ export default src;
97
+ }
98
+ declare module '*.gif' {
99
+ const src: string;
100
+ export default src;
101
+ }
102
+ declare module '*.svg' {
103
+ const src: string;
104
+ export default src;
105
+ }
106
+ declare module '*.ico' {
107
+ const src: string;
108
+ export default src;
109
+ }
110
+ declare module '*.webp' {
111
+ const src: string;
112
+ export default src;
113
+ }
114
+ declare module '*.avif' {
115
+ const src: string;
116
+ export default src;
117
+ }
118
+
119
+ // media
120
+ declare module '*.mp4' {
121
+ const src: string;
122
+ export default src;
123
+ }
124
+ declare module '*.webm' {
125
+ const src: string;
126
+ export default src;
127
+ }
128
+ declare module '*.ogg' {
129
+ const src: string;
130
+ export default src;
131
+ }
132
+ declare module '*.mp3' {
133
+ const src: string;
134
+ export default src;
135
+ }
136
+ declare module '*.wav' {
137
+ const src: string;
138
+ export default src;
139
+ }
140
+ declare module '*.flac' {
141
+ const src: string;
142
+ export default src;
143
+ }
144
+ declare module '*.aac' {
145
+ const src: string;
146
+ export default src;
147
+ }
148
+
149
+ // fonts
150
+ declare module '*.woff' {
151
+ const src: string;
152
+ export default src;
153
+ }
154
+ declare module '*.woff2' {
155
+ const src: string;
156
+ export default src;
157
+ }
158
+ declare module '*.eot' {
159
+ const src: string;
160
+ export default src;
161
+ }
162
+ declare module '*.ttf' {
163
+ const src: string;
164
+ export default src;
165
+ }
166
+ declare module '*.otf' {
167
+ const src: string;
168
+ export default src;
169
+ }
170
+
171
+ // other
172
+ declare module '*.webmanifest' {
173
+ const src: string;
174
+ export default src;
175
+ }
176
+ declare module '*.pdf' {
177
+ const src: string;
178
+ export default src;
179
+ }
180
+ declare module '*.txt' {
181
+ const src: string;
182
+ export default src;
183
+ }
184
+
185
+ // wasm?init
186
+ declare module '*.wasm?init' {
187
+ const initWasm: (options: WebAssembly.Imports) => Promise<WebAssembly.Instance>;
188
+ export default initWasm;
189
+ }
190
+
191
+ // web worker
192
+ declare module '*?worker' {
193
+ const workerConstructor: new () => Worker;
194
+ export default workerConstructor;
195
+ }
196
+
197
+ declare module '*?worker&inline' {
198
+ const workerConstructor: new () => Worker;
199
+ export default workerConstructor;
200
+ }
201
+
202
+ declare module '*?worker&url' {
203
+ const src: string;
204
+ export default src;
205
+ }
206
+
207
+ declare module '*?sharedworker' {
208
+ const sharedWorkerConstructor: new () => SharedWorker;
209
+ export default sharedWorkerConstructor;
210
+ }
211
+
212
+ declare module '*?sharedworker&inline' {
213
+ const sharedWorkerConstructor: new () => SharedWorker;
214
+ export default sharedWorkerConstructor;
215
+ }
216
+
217
+ declare module '*?sharedworker&url' {
218
+ const src: string;
219
+ export default src;
220
+ }
221
+
222
+ declare module '*?raw' {
223
+ const src: string;
224
+ export default src;
225
+ }
226
+
227
+ declare module '*?url' {
228
+ const src: string;
229
+ export default src;
230
+ }
231
+
232
+ declare module '*?inline' {
233
+ const src: string;
234
+ export default src;
235
+ }
236
+
237
+ declare module '*.bmp' {
238
+ const src: string;
239
+ export default src;
240
+ }
@@ -0,0 +1,4 @@
1
+ /* eslint-disable @typescript-eslint/triple-slash-reference */
2
+ /* eslint-disable multiline-comment-style */
3
+ /// <reference types="node" />
4
+ /// <reference types="./files" />
@@ -0,0 +1,5 @@
1
+ /* eslint-disable @typescript-eslint/triple-slash-reference */
2
+ /* eslint-disable multiline-comment-style */
3
+ /// <reference types="./index" />
4
+ /// <reference types="react" />
5
+ /// <reference types="react-dom" />
package/types/vue.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ /* eslint-disable @typescript-eslint/triple-slash-reference */
2
+ /* eslint-disable multiline-comment-style */
3
+ /// <reference types="./index" />