eslint-plugin-nextfriday 1.7.0 → 1.8.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/CHANGELOG.md +10 -0
- package/README.md +11 -8
- package/docs/rules/NO_LAZY_IDENTIFIERS.md +106 -0
- package/lib/index.cjs +270 -131
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +14 -0
- package/lib/index.d.ts +14 -0
- package/lib/index.js +270 -131
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# eslint-plugin-nextfriday
|
|
2
2
|
|
|
3
|
+
## 1.8.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#43](https://github.com/next-friday/eslint-plugin-nextfriday/pull/43) [`2fbee6d`](https://github.com/next-friday/eslint-plugin-nextfriday/commit/2fbee6df84009954cb99674bcdb1cb1cca3be4e6) Thanks [@nextfridaydeveloper](https://github.com/nextfridaydeveloper)! - feat(rules): add no-lazy-identifiers rule
|
|
8
|
+
|
|
9
|
+
Added a new rule `no-lazy-identifiers` that detects and disallows lazy variable names:
|
|
10
|
+
- Repeated characters (3+): `xxx`, `aaa`, `zzz`
|
|
11
|
+
- Keyboard sequences (4+): `asdf`, `qwerty`, `hjkl`, `zxcv`
|
|
12
|
+
|
|
3
13
|
## 1.7.0
|
|
4
14
|
|
|
5
15
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -61,6 +61,7 @@ export default [
|
|
|
61
61
|
rules: {
|
|
62
62
|
// Variable Naming
|
|
63
63
|
"nextfriday/no-single-char-variables": "error",
|
|
64
|
+
"nextfriday/no-lazy-identifiers": "error",
|
|
64
65
|
"nextfriday/boolean-naming-prefix": "error",
|
|
65
66
|
|
|
66
67
|
// File Naming
|
|
@@ -133,6 +134,7 @@ module.exports = {
|
|
|
133
134
|
| Rule | Description | Fixable |
|
|
134
135
|
| ------------------------------------------------------------------ | --------------------------------------------------------------------- | ------- |
|
|
135
136
|
| [no-single-char-variables](docs/rules/NO_SINGLE_CHAR_VARIABLES.md) | Disallow single character variable names (e.g., `d`, `u`, `l`) | ❌ |
|
|
137
|
+
| [no-lazy-identifiers](docs/rules/NO_LAZY_IDENTIFIERS.md) | Disallow lazy identifiers like `xxx`, `asdf`, `qwerty` | ❌ |
|
|
136
138
|
| [boolean-naming-prefix](docs/rules/BOOLEAN_NAMING_PREFIX.md) | Enforce boolean variables to have prefix (is, has, should, can, etc.) | ❌ |
|
|
137
139
|
|
|
138
140
|
### File Naming Rules
|
|
@@ -187,14 +189,14 @@ module.exports = {
|
|
|
187
189
|
|
|
188
190
|
| Preset | Severity | Base Rules | JSX Rules | Total Rules |
|
|
189
191
|
| -------------------- | -------- | ---------- | --------- | ----------- |
|
|
190
|
-
| `base` | warn |
|
|
191
|
-
| `base/recommended` | error |
|
|
192
|
-
| `react` | warn |
|
|
193
|
-
| `react/recommended` | error |
|
|
194
|
-
| `nextjs` | warn |
|
|
195
|
-
| `nextjs/recommended` | error |
|
|
192
|
+
| `base` | warn | 17 | 0 | 17 |
|
|
193
|
+
| `base/recommended` | error | 17 | 0 | 17 |
|
|
194
|
+
| `react` | warn | 17 | 7 | 24 |
|
|
195
|
+
| `react/recommended` | error | 17 | 7 | 24 |
|
|
196
|
+
| `nextjs` | warn | 17 | 7 | 24 |
|
|
197
|
+
| `nextjs/recommended` | error | 17 | 7 | 24 |
|
|
196
198
|
|
|
197
|
-
### Base Configuration Rules (
|
|
199
|
+
### Base Configuration Rules (17 rules)
|
|
198
200
|
|
|
199
201
|
Included in `base`, `base/recommended`, and all other presets:
|
|
200
202
|
|
|
@@ -206,7 +208,7 @@ Included in `base`, `base/recommended`, and all other presets:
|
|
|
206
208
|
- `nextfriday/no-direct-date`
|
|
207
209
|
- `nextfriday/no-emoji`
|
|
208
210
|
- `nextfriday/no-env-fallback`
|
|
209
|
-
- `nextfriday/
|
|
211
|
+
- `nextfriday/no-lazy-identifiers`
|
|
210
212
|
- `nextfriday/no-logic-in-params`
|
|
211
213
|
- `nextfriday/no-single-char-variables`
|
|
212
214
|
- `nextfriday/prefer-destructuring-params`
|
|
@@ -214,6 +216,7 @@ Included in `base`, `base/recommended`, and all other presets:
|
|
|
214
216
|
- `nextfriday/prefer-import-type`
|
|
215
217
|
- `nextfriday/prefer-named-param-types`
|
|
216
218
|
- `nextfriday/prefer-react-import-types`
|
|
219
|
+
- `nextfriday/require-explicit-return-type`
|
|
217
220
|
|
|
218
221
|
### JSX Rules (7 rules)
|
|
219
222
|
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# no-lazy-identifiers
|
|
2
|
+
|
|
3
|
+
Disallow lazy, meaningless variable names that hurt code readability.
|
|
4
|
+
|
|
5
|
+
## Rule Details
|
|
6
|
+
|
|
7
|
+
This rule enforces meaningful variable names by detecting and disallowing lazy identifiers. It uses pattern-based detection to find repeated characters and keyboard sequences.
|
|
8
|
+
|
|
9
|
+
**Incorrect** code for this rule:
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
const xxx = "value";
|
|
13
|
+
const yyy = 123;
|
|
14
|
+
const zzz = true;
|
|
15
|
+
const aaa = [];
|
|
16
|
+
|
|
17
|
+
const asdf = "keyboard pattern";
|
|
18
|
+
const qwerty = "another pattern";
|
|
19
|
+
|
|
20
|
+
function xxx() {
|
|
21
|
+
return 1;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const fn = (xxx) => xxx * 2;
|
|
25
|
+
|
|
26
|
+
class aaaa {}
|
|
27
|
+
|
|
28
|
+
const { xxx } = obj;
|
|
29
|
+
const [aaa, bbb] = array;
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
**Correct** code for this rule:
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
const userName = "john";
|
|
36
|
+
const itemCount = 123;
|
|
37
|
+
const isActive = true;
|
|
38
|
+
const items = [];
|
|
39
|
+
|
|
40
|
+
const keyboardType = "mechanical";
|
|
41
|
+
const inputLayout = "us";
|
|
42
|
+
|
|
43
|
+
function calculateTotal() {
|
|
44
|
+
return 1;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const double = (value) => value * 2;
|
|
48
|
+
|
|
49
|
+
class UserService {}
|
|
50
|
+
|
|
51
|
+
const { name } = obj;
|
|
52
|
+
const [first, second] = array;
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Detection Patterns
|
|
56
|
+
|
|
57
|
+
The rule detects two types of lazy patterns:
|
|
58
|
+
|
|
59
|
+
### Repeated Characters (3+)
|
|
60
|
+
|
|
61
|
+
Variables with 3 or more consecutive identical characters:
|
|
62
|
+
|
|
63
|
+
- `xxx`, `aaa`, `zzz`, `qqqq`, `aaaa`
|
|
64
|
+
|
|
65
|
+
### Keyboard Sequences (4+)
|
|
66
|
+
|
|
67
|
+
Variables containing 4 or more consecutive keyboard row characters:
|
|
68
|
+
|
|
69
|
+
- `asdf`, `qwerty`, `zxcv`, `hjkl`, `1234`
|
|
70
|
+
- Also detects reversed sequences: `fdsa`, `lkjh`
|
|
71
|
+
- Detects sequences embedded in names: `myAsdfVar`
|
|
72
|
+
|
|
73
|
+
## Exceptions
|
|
74
|
+
|
|
75
|
+
### Short Identifiers
|
|
76
|
+
|
|
77
|
+
Identifiers shorter than 3 characters are ignored (use `no-single-char-variables` for those).
|
|
78
|
+
|
|
79
|
+
### Underscore-Prefixed
|
|
80
|
+
|
|
81
|
+
Variables starting with `_` are allowed (commonly used for unused variables):
|
|
82
|
+
|
|
83
|
+
```typescript
|
|
84
|
+
const _unused = getValue();
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Benefits
|
|
88
|
+
|
|
89
|
+
- **Readable code**: Meaningful names make code self-documenting
|
|
90
|
+
- **Maintainability**: Other developers can understand the purpose of variables
|
|
91
|
+
- **Professionalism**: Clean code reflects well on the team
|
|
92
|
+
- **Debugging**: Clear names make debugging easier
|
|
93
|
+
|
|
94
|
+
## When Not To Use
|
|
95
|
+
|
|
96
|
+
- In test files where placeholder data is acceptable
|
|
97
|
+
- When working with legacy code that would be disruptive to change
|
|
98
|
+
|
|
99
|
+
## Configuration
|
|
100
|
+
|
|
101
|
+
This rule has no configuration options.
|
|
102
|
+
|
|
103
|
+
## Related Rules
|
|
104
|
+
|
|
105
|
+
- [no-single-char-variables](./NO_SINGLE_CHAR_VARIABLES.md) - Disallows single character variable names
|
|
106
|
+
- [boolean-naming-prefix](./BOOLEAN_NAMING_PREFIX.md) - Enforces naming conventions for boolean variables
|