mm_machine 2.1.1 → 2.1.3

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.
@@ -0,0 +1,209 @@
1
+ 'use strict';
2
+
3
+ const namingConventionPlugin = require('mm_eslint');
4
+
5
+ /**
6
+ * 基于个人规则的ESLint配置
7
+ * 符合最新ESLint Flat Config格式
8
+ */
9
+
10
+ module.exports = [
11
+ {
12
+ files: ['**/*.js'],
13
+ plugins: {
14
+ 'naming-convention': namingConventionPlugin,
15
+ 'jsdoc': require('eslint-plugin-jsdoc')
16
+ },
17
+ languageOptions: {
18
+ ecmaVersion: 'latest',
19
+ sourceType: 'module',
20
+ parserOptions: {
21
+ ecmaVersion: 'latest',
22
+ sourceType: 'module'
23
+ }
24
+ },
25
+
26
+ // 命名规范规则 - 由自定义插件处理
27
+ rules: {
28
+ // 自定义命名规范插件规则(优先使用)
29
+ 'naming-convention/class-name': 'error',
30
+ 'naming-convention/function-name': 'error',
31
+ 'naming-convention/method-name': 'error',
32
+ 'naming-convention/variable-name': 'warn',
33
+ 'naming-convention/constant-name': 'error',
34
+ 'naming-convention/private-method-naming': 'warn',
35
+ 'naming-convention/private-variable-naming': 'warn',
36
+ 'naming-convention/param-name': 'warn',
37
+ 'naming-convention/property-name': 'warn',
38
+
39
+ // 禁用与命名规范插件冲突的默认规则
40
+ 'camelcase': 'off',
41
+ 'id-match': 'off',
42
+ 'new-cap': 'off',
43
+ 'id-length': 'off',
44
+ 'id-denylist': 'off',
45
+ 'id-blacklist': 'off'
46
+ }
47
+ },
48
+
49
+ {
50
+ // 代码风格规则
51
+ rules: {
52
+ // 最大行长度100字符
53
+ 'max-len': ['error', {
54
+ code: 100,
55
+ ignoreComments: true,
56
+ ignoreUrls: true,
57
+ ignoreStrings: true,
58
+ ignoreTemplateLiterals: true
59
+ }],
60
+
61
+ // 缩进2空格
62
+ 'indent': ['error', 2, {
63
+ SwitchCase: 1,
64
+ VariableDeclarator: 1,
65
+ outerIIFEBody: 1,
66
+ MemberExpression: 1,
67
+ FunctionDeclaration: { parameters: 1, body: 1 },
68
+ FunctionExpression: { parameters: 1, body: 1 },
69
+ CallExpression: { arguments: 1 },
70
+ ArrayExpression: 1,
71
+ ObjectExpression: 1,
72
+ ImportDeclaration: 1,
73
+ flatTernaryExpressions: false,
74
+ ignoreComments: false
75
+ }],
76
+
77
+ // 单引号
78
+ 'quotes': ['error', 'single', {
79
+ avoidEscape: true,
80
+ allowTemplateLiterals: true
81
+ }],
82
+
83
+ // 禁止制表符
84
+ 'no-tabs': 'error',
85
+
86
+ // 行尾分号
87
+ 'semi': ['error', 'always'],
88
+
89
+ // 逗号风格
90
+ 'comma-style': ['error', 'last'],
91
+
92
+ // 逗号间距
93
+ 'comma-spacing': ['error', {
94
+ before: false,
95
+ after: true
96
+ }]
97
+ }
98
+ },
99
+
100
+ {
101
+ // 错误处理规则
102
+ rules: {
103
+ // 必须进行参数校验
104
+ 'no-unused-vars': ['error', {
105
+ args: 'none',
106
+ caughtErrors: 'all',
107
+ caughtErrorsIgnorePattern: '^_',
108
+ destructuredArrayIgnorePattern: '^_',
109
+ varsIgnorePattern: '^_',
110
+ ignoreRestSiblings: true
111
+ }],
112
+
113
+ // 建议使用try-catch
114
+ 'no-unsafe-finally': 'warn',
115
+
116
+ // 禁止直接抛出字符串
117
+ 'no-throw-literal': 'error'
118
+ }
119
+ },
120
+
121
+ {
122
+ // 最佳实践规则
123
+ rules: {
124
+ // 优先使用async/await
125
+ 'prefer-promise-reject-errors': 'error',
126
+
127
+ // 避免副作用
128
+ 'no-param-reassign': ['error', {
129
+ props: true,
130
+ ignorePropertyModificationsFor: [
131
+ 'acc', // for reduce accumulators
132
+ 'accumulator', // for reduce accumulators
133
+ 'e', // for e.returnvalue
134
+ 'ctx', // for Koa routing
135
+ 'context', // for Koa routing
136
+ 'req', // for Express requests
137
+ 'request', // for Express requests
138
+ 'res', // for Express responses
139
+ 'response', // for Express responses
140
+ '$scope', // for Angular 1 scopes
141
+ 'static_context' // for ReactRouter context
142
+ ]
143
+ }],
144
+
145
+ // 优先链式编程
146
+ 'prefer-object-spread': 'error',
147
+
148
+ // 优先函数式编程
149
+ 'prefer-arrow-callback': 'error',
150
+
151
+ // 方法长度限制
152
+ 'max-lines-per-function': ['warn', {
153
+ max: 40,
154
+ skipBlankLines: true,
155
+ skipComments: true
156
+ }],
157
+
158
+ // 复杂度限制
159
+ 'complexity': ['warn', 10]
160
+ }
161
+ },
162
+
163
+ {
164
+ // JSDoc规则
165
+ rules: {
166
+ // 要求公开方法有JSDoc注释
167
+ 'jsdoc/require-jsdoc': ['warn', {
168
+ publicOnly: true,
169
+ require: {
170
+ FunctionDeclaration: true,
171
+ MethodDefinition: true,
172
+ ClassDeclaration: true,
173
+ ArrowFunctionExpression: false,
174
+ FunctionExpression: false
175
+ }
176
+ }],
177
+
178
+ // 检查JSDoc语法
179
+ 'jsdoc/check-alignment': 'warn',
180
+ 'jsdoc/check-indentation': 'warn',
181
+ 'jsdoc/check-param-names': 'warn',
182
+ 'jsdoc/check-syntax': 'warn',
183
+ 'jsdoc/check-tag-names': 'warn',
184
+ 'jsdoc/check-types': 'warn',
185
+ 'jsdoc/no-undefined-types': 'warn',
186
+ 'jsdoc/require-description': 'warn',
187
+ 'jsdoc/require-param': 'warn',
188
+ 'jsdoc/require-param-description': 'warn',
189
+ 'jsdoc/require-param-name': 'warn',
190
+ 'jsdoc/require-param-type': 'warn',
191
+ 'jsdoc/require-returns': 'warn',
192
+ 'jsdoc/require-returns-check': 'warn',
193
+ 'jsdoc/require-returns-description': 'warn',
194
+ 'jsdoc/require-returns-type': 'warn',
195
+ 'jsdoc/valid-types': 'warn'
196
+ }
197
+ },
198
+
199
+ {
200
+ // 忽略规则
201
+ ignores: [
202
+ 'node_modules/**',
203
+ 'dist/**',
204
+ 'build/**',
205
+ 'coverage/**',
206
+ '*.min.js'
207
+ ]
208
+ }
209
+ ];