mm_eslint 1.0.2 → 1.0.4

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 (4) hide show
  1. package/README.md +77 -67
  2. package/README_EN.md +77 -67
  3. package/index.js +1901 -1085
  4. package/package.json +1 -1
package/README.md CHANGED
@@ -43,91 +43,91 @@ cp mm_eslint/index.js your-project/eslint-plugins/
43
43
 
44
44
  ```javascript
45
45
  // eslint.config.js
46
- const namingConventionPlugin = require('mm_eslint');
46
+ const namingConventionPlugin = require("mm_eslint");
47
47
 
48
48
  module.exports = [
49
49
  {
50
- files: ['**/*.js'],
50
+ files: ["**/*.js"],
51
51
  plugins: {
52
- 'naming-convention': namingConventionPlugin,
53
- 'jsdoc': require('eslint-plugin-jsdoc')
52
+ "naming-convention": namingConventionPlugin,
53
+ jsdoc: require("eslint-plugin-jsdoc"),
54
54
  },
55
55
  rules: {
56
56
  // 自定义命名规范插件规则(优先使用)
57
- 'naming-convention/class-name': 'error',
58
- 'naming-convention/function-name': 'error',
59
- 'naming-convention/method-name': 'error',
60
- 'naming-convention/variable-name': 'warn',
61
- 'naming-convention/constant-name': 'error',
62
- 'naming-convention/private-naming': 'warn',
63
- 'naming-convention/param-name': 'warn',
64
- 'naming-convention/property-name': 'warn',
65
-
57
+ "naming-convention/class-name": "error",
58
+ "naming-convention/function-name": "error",
59
+ "naming-convention/method-name": "error",
60
+ "naming-convention/variable-name": "warn",
61
+ "naming-convention/constant-name": "error",
62
+ "naming-convention/private-naming": "warn",
63
+ "naming-convention/param-name": "warn",
64
+ "naming-convention/property-name": "warn",
65
+
66
66
  // 禁用与命名规范插件冲突的默认规则
67
- 'camelcase': 'off',
68
- 'id-match': 'off',
69
- 'new-cap': 'off',
70
- 'id-length': 'off',
71
- 'id-denylist': 'off',
72
- 'id-blacklist': 'off'
73
- }
67
+ camelcase: "off",
68
+ "id-match": "off",
69
+ "new-cap": "off",
70
+ "id-length": "off",
71
+ "id-denylist": "off",
72
+ "id-blacklist": "off",
73
+ },
74
74
  },
75
-
75
+
76
76
  {
77
77
  // 代码风格规则
78
78
  rules: {
79
- 'max-len': ['error', { code: 100 }],
80
- 'indent': ['error', 2],
81
- 'quotes': ['error', 'single'],
82
- 'no-tabs': 'error',
83
- 'semi': ['error', 'always']
84
- }
79
+ "max-len": ["error", { code: 100 }],
80
+ indent: ["error", 2],
81
+ quotes: ["error", "single"],
82
+ "no-tabs": "error",
83
+ semi: ["error", "always"],
84
+ },
85
85
  },
86
-
86
+
87
87
  {
88
88
  // 错误处理规则
89
89
  rules: {
90
- 'no-unused-vars': ['error', { args: 'all' }],
91
- 'no-unsafe-finally': 'warn',
92
- 'no-throw-literal': 'error'
93
- }
90
+ "no-unused-vars": ["error", { args: "all" }],
91
+ "no-unsafe-finally": "warn",
92
+ "no-throw-literal": "error",
93
+ },
94
94
  },
95
-
95
+
96
96
  {
97
97
  // 最佳实践规则
98
98
  rules: {
99
- 'prefer-promise-reject-errors': 'error',
100
- 'no-param-reassign': 'error',
101
- 'prefer-object-spread': 'error',
102
- 'prefer-arrow-callback': 'error',
103
- 'max-lines-per-function': ['warn', { max: 40 }],
104
- 'complexity': ['warn', 10]
105
- }
99
+ "prefer-promise-reject-errors": "error",
100
+ "no-param-reassign": "error",
101
+ "prefer-object-spread": "error",
102
+ "prefer-arrow-callback": "error",
103
+ "max-lines-per-function": ["warn", { max: 40 }],
104
+ complexity: ["warn", 10],
105
+ },
106
106
  },
107
-
107
+
108
108
  {
109
109
  // JSDoc规则
110
110
  rules: {
111
- 'jsdoc/require-jsdoc': ['warn', { publicOnly: true }],
112
- 'jsdoc/check-alignment': 'warn',
113
- 'jsdoc/check-indentation': 'warn',
114
- 'jsdoc/check-param-names': 'warn',
115
- 'jsdoc/check-syntax': 'warn',
116
- 'jsdoc/check-tag-names': 'warn',
117
- 'jsdoc/check-types': 'warn',
118
- 'jsdoc/no-undefined-types': 'warn',
119
- 'jsdoc/require-description': 'warn',
120
- 'jsdoc/require-param': 'warn',
121
- 'jsdoc/require-param-description': 'warn',
122
- 'jsdoc/require-param-name': 'warn',
123
- 'jsdoc/require-param-type': 'warn',
124
- 'jsdoc/require-returns': 'warn',
125
- 'jsdoc/require-returns-check': 'warn',
126
- 'jsdoc/require-returns-description': 'warn',
127
- 'jsdoc/require-returns-type': 'warn',
128
- 'jsdoc/valid-types': 'warn'
129
- }
130
- }
111
+ "jsdoc/require-jsdoc": ["warn", { publicOnly: true }],
112
+ "jsdoc/check-alignment": "warn",
113
+ "jsdoc/check-indentation": "warn",
114
+ "jsdoc/check-param-names": "warn",
115
+ "jsdoc/check-syntax": "warn",
116
+ "jsdoc/check-tag-names": "warn",
117
+ "jsdoc/check-types": "warn",
118
+ "jsdoc/no-undefined-types": "warn",
119
+ "jsdoc/require-description": "warn",
120
+ "jsdoc/require-param": "warn",
121
+ "jsdoc/require-param-description": "warn",
122
+ "jsdoc/require-param-name": "warn",
123
+ "jsdoc/require-param-type": "warn",
124
+ "jsdoc/require-returns": "warn",
125
+ "jsdoc/require-returns-check": "warn",
126
+ "jsdoc/require-returns-description": "warn",
127
+ "jsdoc/require-returns-type": "warn",
128
+ "jsdoc/valid-types": "warn",
129
+ },
130
+ },
131
131
  ];
132
132
  ```
133
133
 
@@ -147,6 +147,7 @@ npx eslint --fix your-file.js
147
147
  ## 命名规范规则
148
148
 
149
149
  ### 类名规则(class-name)
150
+
150
151
  - **级别**: error
151
152
  - **要求**: 大驼峰命名法(PascalCase)
152
153
  - **长度**: 1-20字符
@@ -155,6 +156,7 @@ npx eslint --fix your-file.js
155
156
  - **错误示例**: `UserConfiguration`, `ProductManagement`
156
157
 
157
158
  ### 函数名规则(function-name)
159
+
158
160
  - **级别**: error
159
161
  - **要求**: 小驼峰命名法(camelCase)
160
162
  - **长度**: 1-20字符
@@ -164,6 +166,7 @@ npx eslint --fix your-file.js
164
166
  - **错误示例**: `getConfiguration`, `processInformation`
165
167
 
166
168
  ### 方法名规则(method-name)
169
+
167
170
  - **级别**: error
168
171
  - **要求**: 小驼峰命名法(camelCase)
169
172
  - **长度**: 1-20字符
@@ -173,6 +176,7 @@ npx eslint --fix your-file.js
173
176
  - **错误示例**: `addConfiguration`, `validateAuthentication`
174
177
 
175
178
  ### 变量名规则(variable-name)
179
+
176
180
  - **级别**: warn
177
181
  - **要求**: 小写蛇形命名法(snake_case)
178
182
  - **长度**: 1-20字符
@@ -180,6 +184,7 @@ npx eslint --fix your-file.js
180
184
  - **错误示例**: `userCount`, `MAX_RETRY`
181
185
 
182
186
  ### 常量名规则(constant-name)
187
+
183
188
  - **级别**: error
184
189
  - **要求**: 大写蛇形命名法(UPPER_SNAKE_CASE)
185
190
  - **长度**: 1-20字符
@@ -187,6 +192,7 @@ npx eslint --fix your-file.js
187
192
  - **错误示例**: `maxRetry`, `defaultTimeout`
188
193
 
189
194
  ### 私有成员规则(private-naming)
195
+
190
196
  - **级别**: warn
191
197
  - **要求**: 下划线开头的小写蛇形命名
192
198
  - **长度**: 2-20字符
@@ -194,6 +200,7 @@ npx eslint --fix your-file.js
194
200
  - **错误示例**: `userCount`, `_UserCount`
195
201
 
196
202
  ### 入参名规则(param-name)
203
+
197
204
  - **级别**: warn
198
205
  - **要求**: 小写蛇形命名法(snake_case)
199
206
  - **长度**: 1-20字符
@@ -201,6 +208,7 @@ npx eslint --fix your-file.js
201
208
  - **错误示例**: `userName`, `maxCount`
202
209
 
203
210
  ### 属性名规则(property-name)
211
+
204
212
  - **级别**: warn
205
213
  - **要求**: 基于值类型的多风格命名
206
214
  - **长度**: 1-20字符
@@ -220,7 +228,7 @@ class User {
220
228
  constructor() {
221
229
  this._user_count = 0; // 私有属性正确
222
230
  }
223
-
231
+
224
232
  /**
225
233
  * 获取用户数量
226
234
  * @returns {number} 用户数量
@@ -250,13 +258,13 @@ let user_count = 10; // 变量名正确
250
258
  ```javascript
251
259
  // 自定义配置示例
252
260
  const customConfig = {
253
- 'class-name': {
261
+ "class-name": {
254
262
  regex: /^[A-Z][a-zA-Z]*$/,
255
263
  min: 1,
256
- max: 25, // 扩展最大长度
264
+ max: 25, // 扩展最大长度
257
265
  single_word_len: 10, // 扩展单词长度限制
258
- message: '类名{name}必须使用大驼峰命名法'
259
- }
266
+ message: "类名{name}必须使用大驼峰命名法",
267
+ },
260
268
  };
261
269
 
262
270
  const detector = new NamingDetector(customConfig);
@@ -297,13 +305,15 @@ ISC License
297
305
  ## 更新日志
298
306
 
299
307
  ### v1.1.0
308
+
300
309
  - 添加单词长度验证(每个单词最大8字符)
301
310
  - 添加入参名和属性名检测
302
311
  - 集成JSDoc文档要求
303
312
  - 增强配置,包含完整的ESLint规则
304
313
 
305
314
  ### v1.0.0
315
+
306
316
  - 初始版本发布
307
317
  - 支持类名、函数名、方法名、变量名、常量名、私有成员命名规范检测
308
318
  - 支持长度限制和单个单词优先规则
309
- - 支持禁止废话词检测
319
+ - 支持禁止废话词检测
package/README_EN.md CHANGED
@@ -43,91 +43,91 @@ Import the plugin in your ESLint configuration file:
43
43
 
44
44
  ```javascript
45
45
  // eslint.config.js
46
- const namingConventionPlugin = require('mm-eslint-plugin');
46
+ const namingConventionPlugin = require("mm-eslint-plugin");
47
47
 
48
48
  module.exports = [
49
49
  {
50
- files: ['**/*.js'],
50
+ files: ["**/*.js"],
51
51
  plugins: {
52
- 'naming-convention': namingConventionPlugin,
53
- 'jsdoc': require('eslint-plugin-jsdoc')
52
+ "naming-convention": namingConventionPlugin,
53
+ jsdoc: require("eslint-plugin-jsdoc"),
54
54
  },
55
55
  rules: {
56
56
  // Custom naming convention rules (priority)
57
- 'naming-convention/class-name': 'error',
58
- 'naming-convention/function-name': 'error',
59
- 'naming-convention/method-name': 'error',
60
- 'naming-convention/variable-name': 'warn',
61
- 'naming-convention/constant-name': 'error',
62
- 'naming-convention/private-naming': 'warn',
63
- 'naming-convention/param-name': 'warn',
64
- 'naming-convention/property-name': 'warn',
65
-
57
+ "naming-convention/class-name": "error",
58
+ "naming-convention/function-name": "error",
59
+ "naming-convention/method-name": "error",
60
+ "naming-convention/variable-name": "warn",
61
+ "naming-convention/constant-name": "error",
62
+ "naming-convention/private-naming": "warn",
63
+ "naming-convention/param-name": "warn",
64
+ "naming-convention/property-name": "warn",
65
+
66
66
  // Disable conflicting default rules
67
- 'camelcase': 'off',
68
- 'id-match': 'off',
69
- 'new-cap': 'off',
70
- 'id-length': 'off',
71
- 'id-denylist': 'off',
72
- 'id-blacklist': 'off'
73
- }
67
+ camelcase: "off",
68
+ "id-match": "off",
69
+ "new-cap": "off",
70
+ "id-length": "off",
71
+ "id-denylist": "off",
72
+ "id-blacklist": "off",
73
+ },
74
74
  },
75
-
75
+
76
76
  {
77
77
  // Code style rules
78
78
  rules: {
79
- 'max-len': ['error', { code: 100 }],
80
- 'indent': ['error', 2],
81
- 'quotes': ['error', 'single'],
82
- 'no-tabs': 'error',
83
- 'semi': ['error', 'always']
84
- }
79
+ "max-len": ["error", { code: 100 }],
80
+ indent: ["error", 2],
81
+ quotes: ["error", "single"],
82
+ "no-tabs": "error",
83
+ semi: ["error", "always"],
84
+ },
85
85
  },
86
-
86
+
87
87
  {
88
88
  // Error handling rules
89
89
  rules: {
90
- 'no-unused-vars': ['error', { args: 'all' }],
91
- 'no-unsafe-finally': 'warn',
92
- 'no-throw-literal': 'error'
93
- }
90
+ "no-unused-vars": ["error", { args: "all" }],
91
+ "no-unsafe-finally": "warn",
92
+ "no-throw-literal": "error",
93
+ },
94
94
  },
95
-
95
+
96
96
  {
97
97
  // Best practices
98
98
  rules: {
99
- 'prefer-promise-reject-errors': 'error',
100
- 'no-param-reassign': 'error',
101
- 'prefer-object-spread': 'error',
102
- 'prefer-arrow-callback': 'error',
103
- 'max-lines-per-function': ['warn', { max: 40 }],
104
- 'complexity': ['warn', 10]
105
- }
99
+ "prefer-promise-reject-errors": "error",
100
+ "no-param-reassign": "error",
101
+ "prefer-object-spread": "error",
102
+ "prefer-arrow-callback": "error",
103
+ "max-lines-per-function": ["warn", { max: 40 }],
104
+ complexity: ["warn", 10],
105
+ },
106
106
  },
107
-
107
+
108
108
  {
109
109
  // JSDoc rules
110
110
  rules: {
111
- 'jsdoc/require-jsdoc': ['warn', { publicOnly: true }],
112
- 'jsdoc/check-alignment': 'warn',
113
- 'jsdoc/check-indentation': 'warn',
114
- 'jsdoc/check-param-names': 'warn',
115
- 'jsdoc/check-syntax': 'warn',
116
- 'jsdoc/check-tag-names': 'warn',
117
- 'jsdoc/check-types': 'warn',
118
- 'jsdoc/no-undefined-types': 'warn',
119
- 'jsdoc/require-description': 'warn',
120
- 'jsdoc/require-param': 'warn',
121
- 'jsdoc/require-param-description': 'warn',
122
- 'jsdoc/require-param-name': 'warn',
123
- 'jsdoc/require-param-type': 'warn',
124
- 'jsdoc/require-returns': 'warn',
125
- 'jsdoc/require-returns-check': 'warn',
126
- 'jsdoc/require-returns-description': 'warn',
127
- 'jsdoc/require-returns-type': 'warn',
128
- 'jsdoc/valid-types': 'warn'
129
- }
130
- }
111
+ "jsdoc/require-jsdoc": ["warn", { publicOnly: true }],
112
+ "jsdoc/check-alignment": "warn",
113
+ "jsdoc/check-indentation": "warn",
114
+ "jsdoc/check-param-names": "warn",
115
+ "jsdoc/check-syntax": "warn",
116
+ "jsdoc/check-tag-names": "warn",
117
+ "jsdoc/check-types": "warn",
118
+ "jsdoc/no-undefined-types": "warn",
119
+ "jsdoc/require-description": "warn",
120
+ "jsdoc/require-param": "warn",
121
+ "jsdoc/require-param-description": "warn",
122
+ "jsdoc/require-param-name": "warn",
123
+ "jsdoc/require-param-type": "warn",
124
+ "jsdoc/require-returns": "warn",
125
+ "jsdoc/require-returns-check": "warn",
126
+ "jsdoc/require-returns-description": "warn",
127
+ "jsdoc/require-returns-type": "warn",
128
+ "jsdoc/valid-types": "warn",
129
+ },
130
+ },
131
131
  ];
132
132
  ```
133
133
 
@@ -147,6 +147,7 @@ npx eslint --fix your-file.js
147
147
  ## Naming Convention Rules
148
148
 
149
149
  ### Class Name Rule (class-name)
150
+
150
151
  - **Level**: error
151
152
  - **Requirement**: PascalCase naming convention
152
153
  - **Length**: 1-20 characters
@@ -155,6 +156,7 @@ npx eslint --fix your-file.js
155
156
  - **Invalid Examples**: `UserConfiguration`, `ProductManagement`
156
157
 
157
158
  ### Function Name Rule (function-name)
159
+
158
160
  - **Level**: error
159
161
  - **Requirement**: camelCase naming convention
160
162
  - **Length**: 1-20 characters
@@ -164,6 +166,7 @@ npx eslint --fix your-file.js
164
166
  - **Invalid Examples**: `getConfiguration`, `processInformation`
165
167
 
166
168
  ### Method Name Rule (method-name)
169
+
167
170
  - **Level**: error
168
171
  - **Requirement**: camelCase naming convention
169
172
  - **Length**: 1-20 characters
@@ -173,6 +176,7 @@ npx eslint --fix your-file.js
173
176
  - **Invalid Examples**: `addConfiguration`, `validateAuthentication`
174
177
 
175
178
  ### Variable Name Rule (variable-name)
179
+
176
180
  - **Level**: warn
177
181
  - **Requirement**: snake_case naming convention
178
182
  - **Length**: 1-20 characters
@@ -180,6 +184,7 @@ npx eslint --fix your-file.js
180
184
  - **Invalid Examples**: `userCount`, `MAX_RETRY`
181
185
 
182
186
  ### Constant Name Rule (constant-name)
187
+
183
188
  - **Level**: error
184
189
  - **Requirement**: UPPER_SNAKE_CASE naming convention
185
190
  - **Length**: 1-20 characters
@@ -187,6 +192,7 @@ npx eslint --fix your-file.js
187
192
  - **Invalid Examples**: `maxRetry`, `defaultTimeout`
188
193
 
189
194
  ### Private Member Rule (private-naming)
195
+
190
196
  - **Level**: warn
191
197
  - **Requirement**: underscore-prefixed snake_case naming
192
198
  - **Length**: 2-20 characters
@@ -194,6 +200,7 @@ npx eslint --fix your-file.js
194
200
  - **Invalid Examples**: `userCount`, `_UserCount`
195
201
 
196
202
  ### Parameter Name Rule (param-name)
203
+
197
204
  - **Level**: warn
198
205
  - **Requirement**: snake_case naming convention
199
206
  - **Length**: 1-20 characters
@@ -201,6 +208,7 @@ npx eslint --fix your-file.js
201
208
  - **Invalid Examples**: `userName`, `maxCount`
202
209
 
203
210
  ### Property Name Rule (property-name)
211
+
204
212
  - **Level**: warn
205
213
  - **Requirement**: Multi-style naming based on value type
206
214
  - **Length**: 1-20 characters
@@ -220,7 +228,7 @@ class User {
220
228
  constructor() {
221
229
  this._user_count = 0; // Private property correct
222
230
  }
223
-
231
+
224
232
  /**
225
233
  * Get user count
226
234
  * @returns {number} User count
@@ -250,13 +258,13 @@ You can customize rule parameters through configuration:
250
258
  ```javascript
251
259
  // Custom configuration example
252
260
  const customConfig = {
253
- 'class-name': {
261
+ "class-name": {
254
262
  regex: /^[A-Z][a-zA-Z]*$/,
255
263
  min: 1,
256
- max: 25, // Extend maximum length
264
+ max: 25, // Extend maximum length
257
265
  single_word_len: 10, // Extend word length limit
258
- message: 'Class name {name} must use PascalCase naming convention'
259
- }
266
+ message: "Class name {name} must use PascalCase naming convention",
267
+ },
260
268
  };
261
269
 
262
270
  const detector = new NamingDetector(customConfig);
@@ -297,13 +305,15 @@ Welcome to submit Issues and Pull Requests to improve this plugin.
297
305
  ## Changelog
298
306
 
299
307
  ### v1.1.0
308
+
300
309
  - Added word length validation (max 8 characters per word)
301
310
  - Added parameter name and property name detection
302
311
  - Integrated JSDoc documentation requirements
303
312
  - Enhanced configuration with complete ESLint rules
304
313
 
305
314
  ### v1.0.0
315
+
306
316
  - Initial version release
307
317
  - Support for class name, function name, method name, variable name, constant name, and private member naming convention detection
308
318
  - Support for length restrictions and single word preference rules
309
- - Support for forbidden words detection
319
+ - Support for forbidden words detection