eslint-plugin-nextfriday 1.8.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 CHANGED
@@ -1,5 +1,15 @@
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
+
3
13
  ## 1.8.0
4
14
 
5
15
  ### Minor Changes
package/README.md CHANGED
@@ -78,6 +78,7 @@ export default [
78
78
  "nextfriday/no-logic-in-params": "error",
79
79
  "nextfriday/enforce-sorted-destructuring": "error",
80
80
  "nextfriday/no-env-fallback": "error",
81
+ "nextfriday/no-inline-default-export": "error",
81
82
 
82
83
  // Import Optimization
83
84
  "nextfriday/prefer-import-type": "error",
@@ -157,6 +158,7 @@ module.exports = {
157
158
  | [no-logic-in-params](docs/rules/NO_LOGIC_IN_PARAMS.md) | Disallow logic/conditions in function parameters - extract to const | ❌ |
158
159
  | [enforce-sorted-destructuring](docs/rules/ENFORCE_SORTED_DESTRUCTURING.md) | Enforce alphabetical sorting of destructured properties | ❌ |
159
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 | ❌ |
160
162
  | [no-direct-date](docs/rules/NO_DIRECT_DATE.md) | Disallow direct usage of Date constructor and methods | ❌ |
161
163
 
162
164
  ### Import Optimization Rules
@@ -189,14 +191,14 @@ module.exports = {
189
191
 
190
192
  | Preset | Severity | Base Rules | JSX Rules | Total Rules |
191
193
  | -------------------- | -------- | ---------- | --------- | ----------- |
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 |
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 |
198
200
 
199
- ### Base Configuration Rules (17 rules)
201
+ ### Base Configuration Rules (18 rules)
200
202
 
201
203
  Included in `base`, `base/recommended`, and all other presets:
202
204
 
@@ -208,6 +210,7 @@ Included in `base`, `base/recommended`, and all other presets:
208
210
  - `nextfriday/no-direct-date`
209
211
  - `nextfriday/no-emoji`
210
212
  - `nextfriday/no-env-fallback`
213
+ - `nextfriday/no-inline-default-export`
211
214
  - `nextfriday/no-lazy-identifiers`
212
215
  - `nextfriday/no-logic-in-params`
213
216
  - `nextfriday/no-single-char-variables`
@@ -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