eslint-plugin-nextfriday 1.7.0 → 1.9.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 +20 -0
- package/README.md +14 -8
- package/docs/rules/NO_INLINE_DEFAULT_EXPORT.md +78 -0
- package/docs/rules/NO_LAZY_IDENTIFIERS.md +106 -0
- package/lib/index.cjs +370 -162
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +28 -0
- package/lib/index.d.ts +28 -0
- package/lib/index.js +370 -162
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# eslint-plugin-nextfriday
|
|
2
2
|
|
|
3
|
+
## 1.9.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#45](https://github.com/next-friday/eslint-plugin-nextfriday/pull/45) [`5a00484`](https://github.com/next-friday/eslint-plugin-nextfriday/commit/5a0048400d3a6b7640813b4ba718635c9117ea20) Thanks [@joetakara](https://github.com/joetakara)! - feat(rules): add no-inline-default-export rule
|
|
8
|
+
|
|
9
|
+
Disallow inline default exports. Prefer declaring functions/classes first, then exporting separately.
|
|
10
|
+
- `export default function foo() {}` → Error
|
|
11
|
+
- `function foo() {} export default foo;` → Valid
|
|
12
|
+
|
|
13
|
+
## 1.8.0
|
|
14
|
+
|
|
15
|
+
### Minor Changes
|
|
16
|
+
|
|
17
|
+
- [#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
|
|
18
|
+
|
|
19
|
+
Added a new rule `no-lazy-identifiers` that detects and disallows lazy variable names:
|
|
20
|
+
- Repeated characters (3+): `xxx`, `aaa`, `zzz`
|
|
21
|
+
- Keyboard sequences (4+): `asdf`, `qwerty`, `hjkl`, `zxcv`
|
|
22
|
+
|
|
3
23
|
## 1.7.0
|
|
4
24
|
|
|
5
25
|
### 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
|
|
@@ -77,6 +78,7 @@ export default [
|
|
|
77
78
|
"nextfriday/no-logic-in-params": "error",
|
|
78
79
|
"nextfriday/enforce-sorted-destructuring": "error",
|
|
79
80
|
"nextfriday/no-env-fallback": "error",
|
|
81
|
+
"nextfriday/no-inline-default-export": "error",
|
|
80
82
|
|
|
81
83
|
// Import Optimization
|
|
82
84
|
"nextfriday/prefer-import-type": "error",
|
|
@@ -133,6 +135,7 @@ module.exports = {
|
|
|
133
135
|
| Rule | Description | Fixable |
|
|
134
136
|
| ------------------------------------------------------------------ | --------------------------------------------------------------------- | ------- |
|
|
135
137
|
| [no-single-char-variables](docs/rules/NO_SINGLE_CHAR_VARIABLES.md) | Disallow single character variable names (e.g., `d`, `u`, `l`) | ❌ |
|
|
138
|
+
| [no-lazy-identifiers](docs/rules/NO_LAZY_IDENTIFIERS.md) | Disallow lazy identifiers like `xxx`, `asdf`, `qwerty` | ❌ |
|
|
136
139
|
| [boolean-naming-prefix](docs/rules/BOOLEAN_NAMING_PREFIX.md) | Enforce boolean variables to have prefix (is, has, should, can, etc.) | ❌ |
|
|
137
140
|
|
|
138
141
|
### File Naming Rules
|
|
@@ -155,6 +158,7 @@ module.exports = {
|
|
|
155
158
|
| [no-logic-in-params](docs/rules/NO_LOGIC_IN_PARAMS.md) | Disallow logic/conditions in function parameters - extract to const | ❌ |
|
|
156
159
|
| [enforce-sorted-destructuring](docs/rules/ENFORCE_SORTED_DESTRUCTURING.md) | Enforce alphabetical sorting of destructured properties | ❌ |
|
|
157
160
|
| [no-env-fallback](docs/rules/NO_ENV_FALLBACK.md) | Disallow fallback values for environment variables | ❌ |
|
|
161
|
+
| [no-inline-default-export](docs/rules/NO_INLINE_DEFAULT_EXPORT.md) | Disallow inline default exports - declare first, then export | ❌ |
|
|
158
162
|
| [no-direct-date](docs/rules/NO_DIRECT_DATE.md) | Disallow direct usage of Date constructor and methods | ❌ |
|
|
159
163
|
|
|
160
164
|
### Import Optimization Rules
|
|
@@ -187,14 +191,14 @@ module.exports = {
|
|
|
187
191
|
|
|
188
192
|
| Preset | Severity | Base Rules | JSX Rules | Total Rules |
|
|
189
193
|
| -------------------- | -------- | ---------- | --------- | ----------- |
|
|
190
|
-
| `base` | warn |
|
|
191
|
-
| `base/recommended` | error |
|
|
192
|
-
| `react` | warn |
|
|
193
|
-
| `react/recommended` | error |
|
|
194
|
-
| `nextjs` | warn |
|
|
195
|
-
| `nextjs/recommended` | error |
|
|
194
|
+
| `base` | warn | 18 | 0 | 18 |
|
|
195
|
+
| `base/recommended` | error | 18 | 0 | 18 |
|
|
196
|
+
| `react` | warn | 18 | 7 | 25 |
|
|
197
|
+
| `react/recommended` | error | 18 | 7 | 25 |
|
|
198
|
+
| `nextjs` | warn | 18 | 7 | 25 |
|
|
199
|
+
| `nextjs/recommended` | error | 18 | 7 | 25 |
|
|
196
200
|
|
|
197
|
-
### Base Configuration Rules (
|
|
201
|
+
### Base Configuration Rules (18 rules)
|
|
198
202
|
|
|
199
203
|
Included in `base`, `base/recommended`, and all other presets:
|
|
200
204
|
|
|
@@ -206,7 +210,8 @@ Included in `base`, `base/recommended`, and all other presets:
|
|
|
206
210
|
- `nextfriday/no-direct-date`
|
|
207
211
|
- `nextfriday/no-emoji`
|
|
208
212
|
- `nextfriday/no-env-fallback`
|
|
209
|
-
- `nextfriday/
|
|
213
|
+
- `nextfriday/no-inline-default-export`
|
|
214
|
+
- `nextfriday/no-lazy-identifiers`
|
|
210
215
|
- `nextfriday/no-logic-in-params`
|
|
211
216
|
- `nextfriday/no-single-char-variables`
|
|
212
217
|
- `nextfriday/prefer-destructuring-params`
|
|
@@ -214,6 +219,7 @@ Included in `base`, `base/recommended`, and all other presets:
|
|
|
214
219
|
- `nextfriday/prefer-import-type`
|
|
215
220
|
- `nextfriday/prefer-named-param-types`
|
|
216
221
|
- `nextfriday/prefer-react-import-types`
|
|
222
|
+
- `nextfriday/require-explicit-return-type`
|
|
217
223
|
|
|
218
224
|
### JSX Rules (7 rules)
|
|
219
225
|
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# no-inline-default-export
|
|
2
|
+
|
|
3
|
+
Disallow inline default exports. Prefer declaring first, then exporting separately.
|
|
4
|
+
|
|
5
|
+
## Rule Details
|
|
6
|
+
|
|
7
|
+
This rule enforces separating function/class declarations from their default exports. Instead of combining declaration and export in a single statement, declare the function or class first, then export it by reference.
|
|
8
|
+
|
|
9
|
+
This pattern improves code readability and makes it easier to identify what a module exports at a glance.
|
|
10
|
+
|
|
11
|
+
## Examples
|
|
12
|
+
|
|
13
|
+
### Incorrect
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
// Inline function default export
|
|
17
|
+
export default function generator(plop: PlopTypes.NodePlopAPI): void {
|
|
18
|
+
// ...
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Inline class default export
|
|
22
|
+
export default class MyService {
|
|
23
|
+
// ...
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Anonymous function default export
|
|
27
|
+
export default function () {
|
|
28
|
+
return "anonymous";
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Arrow function default export
|
|
32
|
+
export default () => "arrow";
|
|
33
|
+
|
|
34
|
+
// Anonymous class default export
|
|
35
|
+
export default class {
|
|
36
|
+
// ...
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Correct
|
|
41
|
+
|
|
42
|
+
```typescript
|
|
43
|
+
// Separate function declaration and export
|
|
44
|
+
function generator(plop: PlopTypes.NodePlopAPI): void {
|
|
45
|
+
// ...
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export default generator;
|
|
49
|
+
|
|
50
|
+
// Separate class declaration and export
|
|
51
|
+
class MyService {
|
|
52
|
+
// ...
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export default MyService;
|
|
56
|
+
|
|
57
|
+
// Separate const arrow function and export
|
|
58
|
+
const processData = (data: Data): Result => {
|
|
59
|
+
// ...
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export default processData;
|
|
63
|
+
|
|
64
|
+
// Exporting literals and objects is allowed
|
|
65
|
+
export default "literal";
|
|
66
|
+
export default { key: "value" };
|
|
67
|
+
|
|
68
|
+
// Re-exports are allowed
|
|
69
|
+
export { foo as default } from "./foo";
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## When Not To Use
|
|
73
|
+
|
|
74
|
+
If your project prefers inline default exports for brevity, or if you're working with frameworks that expect specific export patterns, you may want to disable this rule.
|
|
75
|
+
|
|
76
|
+
## Related Rules
|
|
77
|
+
|
|
78
|
+
- [prefer-function-declaration](./PREFER_FUNCTION_DECLARATION.md) - Prefer function declarations over expressions
|
|
@@ -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
|