mm_eslint 1.4.1 → 1.4.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.
- package/config.js +81 -45
- package/detector.js +2374 -376
- package/index.js +977 -77
- package/package.json +1 -1
- package/README_EN.md +0 -410
package/package.json
CHANGED
package/README_EN.md
DELETED
|
@@ -1,410 +0,0 @@
|
|
|
1
|
-
# MM ESLint Plugin
|
|
2
|
-
|
|
3
|
-
An ESLint plugin based on personal naming conventions, supporting naming convention detection for class names, function names, variable names, constant names, and more.
|
|
4
|
-
|
|
5
|
-
## Features
|
|
6
|
-
|
|
7
|
-
- ✅ **Class Name Detection** - PascalCase naming convention
|
|
8
|
-
- ✅ **Function Name Detection** - camelCase naming convention
|
|
9
|
-
- ✅ **Method Name Detection** - camelCase naming convention
|
|
10
|
-
- ✅ **Variable Name Detection** - snake_case naming convention
|
|
11
|
-
- ✅ **Constant Name Detection** - UPPER_SNAKE_CASE naming convention
|
|
12
|
-
- ✅ **Private Member Detection** - underscore-prefixed snake_case naming
|
|
13
|
-
- ✅ **Parameter Name Detection** - snake_case naming convention
|
|
14
|
-
- ✅ **Property Name Detection** - Multi-style naming based on value type
|
|
15
|
-
- ✅ **Length Restrictions** - All names limited to 1-20 characters
|
|
16
|
-
- ✅ **Single Word Preferred** - Encourages single word naming
|
|
17
|
-
- ✅ **Word Length Limit** - Each word limited to maximum 8 characters
|
|
18
|
-
- ✅ **Forbidden Words** - Avoids redundant words like Manager, Handler, etc.
|
|
19
|
-
- ✅ **JSDoc Support** - Integrated JSDoc documentation requirements
|
|
20
|
-
- ✅ **Naming Recommendations** - Recommends shorter alternative names while preserving semantic meaning
|
|
21
|
-
|
|
22
|
-
## Installation
|
|
23
|
-
|
|
24
|
-
### npm Installation
|
|
25
|
-
|
|
26
|
-
```bash
|
|
27
|
-
npm install mm-eslint-plugin --save-dev
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
### Local Installation
|
|
31
|
-
|
|
32
|
-
If you want to use a local version, you can copy the plugin files to your project:
|
|
33
|
-
|
|
34
|
-
```bash
|
|
35
|
-
# Copy plugin files to your project
|
|
36
|
-
cp mm-eslint-plugin/index.js your-project/eslint-plugins/
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
## Quick Start
|
|
40
|
-
|
|
41
|
-
### 1. Complete Configuration
|
|
42
|
-
|
|
43
|
-
Import the plugin in your ESLint configuration file:
|
|
44
|
-
|
|
45
|
-
```javascript
|
|
46
|
-
// eslint.config.js
|
|
47
|
-
const namingConventionPlugin = require("mm-eslint-plugin");
|
|
48
|
-
|
|
49
|
-
module.exports = [
|
|
50
|
-
{
|
|
51
|
-
files: ["**/*.js"],
|
|
52
|
-
plugins: {
|
|
53
|
-
"naming-convention": namingConventionPlugin,
|
|
54
|
-
jsdoc: require("eslint-plugin-jsdoc"),
|
|
55
|
-
},
|
|
56
|
-
rules: {
|
|
57
|
-
// Custom naming convention rules (priority)
|
|
58
|
-
"naming-convention/class-name": "error",
|
|
59
|
-
"naming-convention/function-name": "error",
|
|
60
|
-
"naming-convention/method-name": "error",
|
|
61
|
-
"naming-convention/variable-name": "warn",
|
|
62
|
-
"naming-convention/constant-name": "error",
|
|
63
|
-
"naming-convention/private-naming": "warn",
|
|
64
|
-
"naming-convention/param-name": "warn",
|
|
65
|
-
"naming-convention/property-name": "warn",
|
|
66
|
-
|
|
67
|
-
// Disable conflicting default rules
|
|
68
|
-
camelcase: "off",
|
|
69
|
-
"id-match": "off",
|
|
70
|
-
"new-cap": "off",
|
|
71
|
-
"id-length": "off",
|
|
72
|
-
"id-denylist": "off",
|
|
73
|
-
"id-blacklist": "off",
|
|
74
|
-
},
|
|
75
|
-
},
|
|
76
|
-
|
|
77
|
-
{
|
|
78
|
-
// Code style rules
|
|
79
|
-
rules: {
|
|
80
|
-
"max-len": ["error", { code: 100 }],
|
|
81
|
-
indent: ["error", 2],
|
|
82
|
-
quotes: ["error", "single"],
|
|
83
|
-
"no-tabs": "error",
|
|
84
|
-
semi: ["error", "always"],
|
|
85
|
-
},
|
|
86
|
-
},
|
|
87
|
-
|
|
88
|
-
{
|
|
89
|
-
// Error handling rules
|
|
90
|
-
rules: {
|
|
91
|
-
"no-unused-vars": ["error", { args: "all" }],
|
|
92
|
-
"no-unsafe-finally": "warn",
|
|
93
|
-
"no-throw-literal": "error",
|
|
94
|
-
},
|
|
95
|
-
},
|
|
96
|
-
|
|
97
|
-
{
|
|
98
|
-
// Best practices
|
|
99
|
-
rules: {
|
|
100
|
-
"prefer-promise-reject-errors": "error",
|
|
101
|
-
"no-param-reassign": "error",
|
|
102
|
-
"prefer-object-spread": "error",
|
|
103
|
-
"prefer-arrow-callback": "error",
|
|
104
|
-
"max-lines-per-function": ["warn", { max: 40 }],
|
|
105
|
-
complexity: ["warn", 10],
|
|
106
|
-
},
|
|
107
|
-
},
|
|
108
|
-
|
|
109
|
-
{
|
|
110
|
-
// JSDoc rules
|
|
111
|
-
rules: {
|
|
112
|
-
"jsdoc/require-jsdoc": ["warn", { publicOnly: true }],
|
|
113
|
-
"jsdoc/check-alignment": "warn",
|
|
114
|
-
"jsdoc/check-indentation": "warn",
|
|
115
|
-
"jsdoc/check-param-names": "warn",
|
|
116
|
-
"jsdoc/check-syntax": "warn",
|
|
117
|
-
"jsdoc/check-tag-names": "warn",
|
|
118
|
-
"jsdoc/check-types": "warn",
|
|
119
|
-
"jsdoc/no-undefined-types": "warn",
|
|
120
|
-
"jsdoc/require-description": "warn",
|
|
121
|
-
"jsdoc/require-param": "warn",
|
|
122
|
-
"jsdoc/require-param-description": "warn",
|
|
123
|
-
"jsdoc/require-param-name": "warn",
|
|
124
|
-
"jsdoc/require-param-type": "warn",
|
|
125
|
-
"jsdoc/require-returns": "warn",
|
|
126
|
-
"jsdoc/require-returns-check": "warn",
|
|
127
|
-
"jsdoc/require-returns-description": "warn",
|
|
128
|
-
"jsdoc/require-returns-type": "warn",
|
|
129
|
-
"jsdoc/valid-types": "warn",
|
|
130
|
-
},
|
|
131
|
-
},
|
|
132
|
-
];
|
|
133
|
-
```
|
|
134
|
-
|
|
135
|
-
### 2. Command Line Usage
|
|
136
|
-
|
|
137
|
-
```bash
|
|
138
|
-
# Validate a single file
|
|
139
|
-
npx eslint your-file.js
|
|
140
|
-
|
|
141
|
-
# Validate all JS files
|
|
142
|
-
npx eslint "**/*.js"
|
|
143
|
-
|
|
144
|
-
# Validate and auto-fix
|
|
145
|
-
npx eslint --fix your-file.js
|
|
146
|
-
```
|
|
147
|
-
|
|
148
|
-
## Naming Convention Rules
|
|
149
|
-
|
|
150
|
-
### Class Name Rule (class-name)
|
|
151
|
-
|
|
152
|
-
- **Level**: error
|
|
153
|
-
- **Requirement**: PascalCase naming convention
|
|
154
|
-
- **Length**: 1-20 characters
|
|
155
|
-
- **Word Length**: Each word ≤8 characters
|
|
156
|
-
- **Examples**: `User`, `Product`
|
|
157
|
-
- **Invalid Examples**: `UserConfiguration`, `ProductManagement`
|
|
158
|
-
|
|
159
|
-
### Function Name Rule (function-name)
|
|
160
|
-
|
|
161
|
-
- **Level**: error
|
|
162
|
-
- **Requirement**: camelCase naming convention
|
|
163
|
-
- **Length**: 1-20 characters
|
|
164
|
-
- **Word Length**: Each word ≤8 characters
|
|
165
|
-
- **Preference**: Single word
|
|
166
|
-
- **Examples**: `get`, `getName`, `process`
|
|
167
|
-
- **Invalid Examples**: `getConfiguration`, `processInformation`
|
|
168
|
-
|
|
169
|
-
### Method Name Rule (method-name)
|
|
170
|
-
|
|
171
|
-
- **Level**: error
|
|
172
|
-
- **Requirement**: camelCase naming convention
|
|
173
|
-
- **Length**: 1-20 characters
|
|
174
|
-
- **Word Length**: Each word ≤8 characters
|
|
175
|
-
- **Preference**: Single word
|
|
176
|
-
- **Examples**: `add`, `setName`, `isValid`
|
|
177
|
-
- **Invalid Examples**: `addConfiguration`, `validateAuthentication`
|
|
178
|
-
|
|
179
|
-
### Variable Name Rule (variable-name)
|
|
180
|
-
|
|
181
|
-
- **Level**: warn
|
|
182
|
-
- **Requirement**: snake_case naming convention
|
|
183
|
-
- **Length**: 1-20 characters
|
|
184
|
-
- **Examples**: `user_count`, `max_retry`
|
|
185
|
-
- **Invalid Examples**: `userCount`, `MAX_RETRY`
|
|
186
|
-
|
|
187
|
-
### Constant Name Rule (constant-name)
|
|
188
|
-
|
|
189
|
-
- **Level**: error
|
|
190
|
-
- **Requirement**: UPPER_SNAKE_CASE naming convention
|
|
191
|
-
- **Length**: 1-20 characters
|
|
192
|
-
- **Examples**: `MAX_RETRY`, `DEFAULT_TIMEOUT`
|
|
193
|
-
- **Invalid Examples**: `maxRetry`, `defaultTimeout`
|
|
194
|
-
|
|
195
|
-
### Private Member Rule (private-naming)
|
|
196
|
-
|
|
197
|
-
- **Level**: warn
|
|
198
|
-
- **Requirement**: underscore-prefixed snake_case naming
|
|
199
|
-
- **Length**: 2-20 characters
|
|
200
|
-
- **Examples**: `_user_count`, `_internal_data`
|
|
201
|
-
- **Invalid Examples**: `userCount`, `_UserCount`
|
|
202
|
-
|
|
203
|
-
### Parameter Name Rule (param-name)
|
|
204
|
-
|
|
205
|
-
- **Level**: warn
|
|
206
|
-
- **Requirement**: snake_case naming convention
|
|
207
|
-
- **Length**: 1-20 characters
|
|
208
|
-
- **Examples**: `user_name`, `max_count`
|
|
209
|
-
- **Invalid Examples**: `userName`, `maxCount`
|
|
210
|
-
|
|
211
|
-
### Property Name Rule (property-name)
|
|
212
|
-
|
|
213
|
-
- **Level**: warn
|
|
214
|
-
- **Requirement**: Multi-style naming based on value type
|
|
215
|
-
- **Length**: 1-20 characters
|
|
216
|
-
- **Examples**: `user_name` (string), `getUser` (function), `User` (class)
|
|
217
|
-
|
|
218
|
-
## Error Examples
|
|
219
|
-
|
|
220
|
-
```javascript
|
|
221
|
-
// ❌ Invalid naming examples
|
|
222
|
-
class UserConfiguration { // "Configuration" exceeds 8 characters
|
|
223
|
-
const getConfiguration = function() {}; // "Configuration" exceeds 8 characters
|
|
224
|
-
let maxRetryCount = 5; // Variable name should be snake_case
|
|
225
|
-
const userCount = 10; // Constant name should be UPPER_SNAKE_CASE
|
|
226
|
-
|
|
227
|
-
// ✅ Correct naming examples
|
|
228
|
-
class User {
|
|
229
|
-
constructor() {
|
|
230
|
-
this._user_count = 0; // Private property correct
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
/**
|
|
234
|
-
* Get user count
|
|
235
|
-
* @returns {number} User count
|
|
236
|
-
*/
|
|
237
|
-
get() { // Method name correct (single word ≤8 chars)
|
|
238
|
-
return this._user_count;
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
const MAX_RETRY = 5; // Constant name correct
|
|
243
|
-
let user_count = 10; // Variable name correct
|
|
244
|
-
```
|
|
245
|
-
|
|
246
|
-
## Word Length Validation
|
|
247
|
-
|
|
248
|
-
The plugin validates that each word in compound names does not exceed 8 characters:
|
|
249
|
-
|
|
250
|
-
- **Valid**: `UserService` ("User"=4, "Service"=7)
|
|
251
|
-
- **Invalid**: `UserConfiguration` ("Configuration"=13 > 8)
|
|
252
|
-
- **Valid**: `getUser` ("get"=3, "User"=4)
|
|
253
|
-
- **Invalid**: `getConfiguration` ("Configuration"=13 > 8)
|
|
254
|
-
|
|
255
|
-
## Configuration Options
|
|
256
|
-
|
|
257
|
-
You can customize rule parameters through configuration:
|
|
258
|
-
|
|
259
|
-
````javascript
|
|
260
|
-
// Custom configuration example
|
|
261
|
-
const customConfig = {
|
|
262
|
-
"class-name": {
|
|
263
|
-
regex: /^[A-Z][a-zA-Z]*$/,
|
|
264
|
-
min: 1,
|
|
265
|
-
max: 25, // Extend maximum length
|
|
266
|
-
single_word_len: 10, // Extend word length limit
|
|
267
|
-
message: "Class name {name} must use PascalCase naming convention",
|
|
268
|
-
},
|
|
269
|
-
};
|
|
270
|
-
|
|
271
|
-
const detector = new NamingDetector(customConfig);
|
|
272
|
-
|
|
273
|
-
## Naming Recommendation Feature
|
|
274
|
-
|
|
275
|
-
The plugin includes an intelligent naming recommendation system that suggests shorter alternative names while preserving semantic meaning.
|
|
276
|
-
|
|
277
|
-
### Principle
|
|
278
|
-
|
|
279
|
-
The core principle is **"shorten names without changing semantics"**. The recommendation system:
|
|
280
|
-
- Recommends shorter words that maintain the same meaning
|
|
281
|
-
- Avoids conceptual changes that would alter functionality
|
|
282
|
-
- Ensures recommended words are always shorter than the original
|
|
283
|
-
- Preserves programming-specific terminology and conceptual differences
|
|
284
|
-
|
|
285
|
-
### Configuration
|
|
286
|
-
|
|
287
|
-
Enable the recommendation feature in your ESLint configuration:
|
|
288
|
-
|
|
289
|
-
```javascript
|
|
290
|
-
// eslint.config.js
|
|
291
|
-
const namingConventionPlugin = require("mm-eslint-plugin");
|
|
292
|
-
|
|
293
|
-
module.exports = [
|
|
294
|
-
{
|
|
295
|
-
files: ["**/*.js"],
|
|
296
|
-
plugins: {
|
|
297
|
-
"naming-convention": namingConventionPlugin,
|
|
298
|
-
},
|
|
299
|
-
rules: {
|
|
300
|
-
"naming-convention/class-name": "error",
|
|
301
|
-
"naming-convention/function-name": ["error", { recommen: true }], // Enable recommendations
|
|
302
|
-
// ... other rules
|
|
303
|
-
},
|
|
304
|
-
},
|
|
305
|
-
];
|
|
306
|
-
````
|
|
307
|
-
|
|
308
|
-
### Available Recommendations
|
|
309
|
-
|
|
310
|
-
The plugin provides recommendations for common programming operations:
|
|
311
|
-
|
|
312
|
-
| Original Word | Recommended Word | Description |
|
|
313
|
-
| ------------- | ---------------- | ------------------------- |
|
|
314
|
-
| `calculate` | `calc` | Mathematical operations |
|
|
315
|
-
| `generate` | `gen` | Data generation |
|
|
316
|
-
| `initialize` | `init` | Initialization operations |
|
|
317
|
-
| `execute` | `exec` | Command execution |
|
|
318
|
-
| `process` | `run` | Data processing |
|
|
319
|
-
| `retrieve` | `load` | Data loading |
|
|
320
|
-
| `persist` | `save` | Data storage |
|
|
321
|
-
| `compare` | `cmp` | Comparison operations |
|
|
322
|
-
| `duplicate` | `copy` | Data copying |
|
|
323
|
-
| `transfer` | `move` | Data movement |
|
|
324
|
-
| `convert` | `to` | Type conversion |
|
|
325
|
-
| `verify` | `check` | Validation checks |
|
|
326
|
-
| `construct` | `create` | Object creation |
|
|
327
|
-
| `handle` | `run` | Event handling |
|
|
328
|
-
|
|
329
|
-
### Examples
|
|
330
|
-
|
|
331
|
-
```javascript
|
|
332
|
-
// ❌ Original (longer names)
|
|
333
|
-
function calculateTotal() {}
|
|
334
|
-
function generateUserData() {}
|
|
335
|
-
function initializeSystem() {}
|
|
336
|
-
function executeCommand() {}
|
|
337
|
-
function processData() {}
|
|
338
|
-
|
|
339
|
-
// ✅ Recommended (shorter names)
|
|
340
|
-
function calcTotal() {}
|
|
341
|
-
function genUserData() {}
|
|
342
|
-
function initSystem() {}
|
|
343
|
-
function execCommand() {}
|
|
344
|
-
function runData() {}
|
|
345
|
-
```
|
|
346
|
-
|
|
347
|
-
### Error Messages with Recommendations
|
|
348
|
-
|
|
349
|
-
When the recommendation feature is enabled, ESLint will suggest alternative names:
|
|
350
|
-
|
|
351
|
-
```bash
|
|
352
|
-
# ESLint output example
|
|
353
|
-
function calculateTotal() {}
|
|
354
|
-
# ^ Recommend using 'calc' instead of 'calculate' for shorter naming
|
|
355
|
-
```
|
|
356
|
-
|
|
357
|
-
### Benefits
|
|
358
|
-
|
|
359
|
-
1. **Improved Readability**: Shorter names are easier to read and understand
|
|
360
|
-
2. **Consistent Codebase**: Standardized naming across the project
|
|
361
|
-
3. **Semantic Preservation**: Meaning is maintained while reducing verbosity
|
|
362
|
-
4. **Programming Best Practices**: Follows industry standards for concise naming
|
|
363
|
-
|
|
364
|
-
## Development
|
|
365
|
-
|
|
366
|
-
### Project Structure
|
|
367
|
-
|
|
368
|
-
```
|
|
369
|
-
mm-eslint-plugin/
|
|
370
|
-
├── index.js # Main plugin file
|
|
371
|
-
├── package.json # npm configuration
|
|
372
|
-
├── eslint.config.js # ESLint configuration
|
|
373
|
-
├── test.js # Unit tests
|
|
374
|
-
├── example.js # Usage examples
|
|
375
|
-
└── README.md # Documentation
|
|
376
|
-
```
|
|
377
|
-
|
|
378
|
-
### Running Tests
|
|
379
|
-
|
|
380
|
-
```bash
|
|
381
|
-
# Run unit tests
|
|
382
|
-
npm test
|
|
383
|
-
|
|
384
|
-
# Run ESLint checks
|
|
385
|
-
npm run lint
|
|
386
|
-
```
|
|
387
|
-
|
|
388
|
-
## License
|
|
389
|
-
|
|
390
|
-
ISC License
|
|
391
|
-
|
|
392
|
-
## Contributing
|
|
393
|
-
|
|
394
|
-
Welcome to submit Issues and Pull Requests to improve this plugin.
|
|
395
|
-
|
|
396
|
-
## Changelog
|
|
397
|
-
|
|
398
|
-
### v1.1.0
|
|
399
|
-
|
|
400
|
-
- Added word length validation (max 8 characters per word)
|
|
401
|
-
- Added parameter name and property name detection
|
|
402
|
-
- Integrated JSDoc documentation requirements
|
|
403
|
-
- Enhanced configuration with complete ESLint rules
|
|
404
|
-
|
|
405
|
-
### v1.0.0
|
|
406
|
-
|
|
407
|
-
- Initial version release
|
|
408
|
-
- Support for class name, function name, method name, variable name, constant name, and private member naming convention detection
|
|
409
|
-
- Support for length restrictions and single word preference rules
|
|
410
|
-
- Support for forbidden words detection
|