eslint-plugin-nextfriday 1.15.2 → 1.17.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 +12 -0
- package/README.md +29 -37
- package/docs/rules/BOOLEAN_NAMING_PREFIX.md +7 -17
- package/docs/rules/ENFORCE_CONSTANT_CASE.md +5 -18
- package/docs/rules/ENFORCE_CURLY_NEWLINE.md +4 -4
- package/docs/rules/ENFORCE_HOOK_NAMING.md +5 -12
- package/docs/rules/ENFORCE_PROPS_SUFFIX.md +3 -21
- package/docs/rules/ENFORCE_READONLY_COMPONENT_PROPS.md +3 -12
- package/docs/rules/ENFORCE_SERVICE_NAMING.md +5 -9
- package/docs/rules/ENFORCE_SORTED_DESTRUCTURING.md +2 -2
- package/docs/rules/ENFORCE_TYPE_DECLARATION_ORDER.md +87 -0
- package/docs/rules/FILE_KEBAB_CASE.md +4 -54
- package/docs/rules/JSX_NEWLINE_BETWEEN_ELEMENTS.md +3 -3
- package/docs/rules/JSX_NO_INLINE_OBJECT_PROP.md +2 -2
- package/docs/rules/JSX_NO_NEWLINE_SINGLE_LINE_ELEMENTS.md +4 -2
- package/docs/rules/JSX_NO_NON_COMPONENT_FUNCTION.md +3 -3
- package/docs/rules/JSX_NO_VARIABLE_IN_CALLBACK.md +2 -2
- package/docs/rules/JSX_PASCAL_CASE.md +3 -43
- package/docs/rules/JSX_REQUIRE_SUSPENSE.md +2 -2
- package/docs/rules/JSX_SIMPLE_PROPS.md +2 -2
- package/docs/rules/JSX_SORT_PROPS.md +11 -8
- package/docs/rules/MD_FILENAME_CASE_RESTRICTION.md +4 -56
- package/docs/rules/NEWLINE_AFTER_MULTILINE_BLOCK.md +3 -3
- package/docs/rules/NEWLINE_BEFORE_RETURN.md +3 -3
- package/docs/rules/NEXTJS_REQUIRE_PUBLIC_ENV.md +3 -19
- package/docs/rules/NO_COMPLEX_INLINE_RETURN.md +7 -16
- package/docs/rules/NO_DIRECT_DATE.md +2 -2
- package/docs/rules/NO_EMOJI.md +4 -4
- package/docs/rules/NO_ENV_FALLBACK.md +2 -2
- package/docs/rules/NO_INLINE_DEFAULT_EXPORT.md +7 -11
- package/docs/rules/NO_INLINE_NESTED_OBJECT.md +3 -9
- package/docs/rules/NO_LAZY_IDENTIFIERS.md +8 -17
- package/docs/rules/NO_LOGIC_IN_PARAMS.md +7 -13
- package/docs/rules/NO_NESTED_INTERFACE_DECLARATION.md +102 -0
- package/docs/rules/NO_NESTED_TERNARY.md +4 -4
- package/docs/rules/NO_RELATIVE_IMPORTS.md +4 -4
- package/docs/rules/NO_SINGLE_CHAR_VARIABLES.md +9 -19
- package/docs/rules/PREFER_ASYNC_AWAIT.md +4 -4
- package/docs/rules/PREFER_DESTRUCTURING_PARAMS.md +7 -16
- package/docs/rules/PREFER_FUNCTION_DECLARATION.md +13 -24
- package/docs/rules/PREFER_GUARD_CLAUSE.md +4 -4
- package/docs/rules/PREFER_IMPORT_TYPE.md +9 -22
- package/docs/rules/PREFER_INLINE_LITERAL_UNION.md +87 -0
- package/docs/rules/PREFER_INTERFACE_OVER_INLINE_TYPES.md +7 -103
- package/docs/rules/PREFER_JSX_TEMPLATE_LITERALS.md +4 -2
- package/docs/rules/PREFER_NAMED_PARAM_TYPES.md +11 -83
- package/docs/rules/PREFER_REACT_IMPORT_TYPES.md +6 -57
- package/docs/rules/REACT_PROPS_DESTRUCTURE.md +6 -65
- package/docs/rules/REQUIRE_EXPLICIT_RETURN_TYPE.md +11 -21
- package/docs/rules/SORT_EXPORTS.md +2 -2
- package/docs/rules/SORT_IMPORTS.md +2 -2
- package/docs/rules/SORT_TYPE_ALPHABETICALLY.md +2 -2
- package/docs/rules/SORT_TYPE_REQUIRED_FIRST.md +2 -2
- package/lib/index.cjs +1152 -937
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +112 -70
- package/lib/index.d.ts +112 -70
- package/lib/index.js +1173 -958
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# eslint-plugin-nextfriday
|
|
2
2
|
|
|
3
|
+
## 1.17.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#79](https://github.com/next-friday/eslint-plugin-nextfriday/pull/79) [`cb5ab46`](https://github.com/next-friday/eslint-plugin-nextfriday/commit/cb5ab460f758e1e57f9604417b673362ec6c71d8) Thanks [@joetakara](https://github.com/joetakara)! - Add expression group to jsx-sort-props rule for variable references, member expressions, and other dynamic values
|
|
8
|
+
|
|
9
|
+
## 1.16.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- [#75](https://github.com/next-friday/eslint-plugin-nextfriday/pull/75) [`f506561`](https://github.com/next-friday/eslint-plugin-nextfriday/commit/f506561c1587af4a129801dee87c7ed08154b090) Thanks [@joetakara](https://github.com/joetakara)! - feat(rules): add prefer-inline-literal-union, no-nested-interface-declaration, and enforce-type-declaration-order rules
|
|
14
|
+
|
|
3
15
|
## 1.15.2
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -48,7 +48,7 @@ export default [nextfriday.configs["nextjs/recommended"]];
|
|
|
48
48
|
|
|
49
49
|
#### Bundled Plugin Configs
|
|
50
50
|
|
|
51
|
-
Pre-configured configs for popular plugins. No extra install needed — they ship as dependencies.
|
|
51
|
+
Pre-configured configs for popular plugins. No extra install needed — they ship as dependencies. These configs are arrays, so use the spread operator (`...`) to merge them into your flat config.
|
|
52
52
|
|
|
53
53
|
```js
|
|
54
54
|
import nextfriday from "eslint-plugin-nextfriday";
|
|
@@ -113,7 +113,10 @@ export default [
|
|
|
113
113
|
"nextfriday/sort-imports": "error",
|
|
114
114
|
|
|
115
115
|
// Type Patterns
|
|
116
|
+
"nextfriday/enforce-type-declaration-order": "error",
|
|
117
|
+
"nextfriday/no-nested-interface-declaration": "error",
|
|
116
118
|
"nextfriday/prefer-named-param-types": "error",
|
|
119
|
+
"nextfriday/prefer-inline-literal-union": "error",
|
|
117
120
|
"nextfriday/prefer-interface-over-inline-types": "error",
|
|
118
121
|
"nextfriday/sort-type-alphabetically": "error",
|
|
119
122
|
"nextfriday/sort-type-required-first": "error",
|
|
@@ -139,34 +142,7 @@ export default [
|
|
|
139
142
|
];
|
|
140
143
|
```
|
|
141
144
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
#### Base Legacy Configuration
|
|
145
|
-
|
|
146
|
-
```js
|
|
147
|
-
module.exports = {
|
|
148
|
-
plugins: ["nextfriday"],
|
|
149
|
-
extends: ["plugin:nextfriday/base"], // or "plugin:nextfriday/base/recommended"
|
|
150
|
-
};
|
|
151
|
-
```
|
|
152
|
-
|
|
153
|
-
#### React Legacy Configuration
|
|
154
|
-
|
|
155
|
-
```js
|
|
156
|
-
module.exports = {
|
|
157
|
-
plugins: ["nextfriday"],
|
|
158
|
-
extends: ["plugin:nextfriday/react"], // or "plugin:nextfriday/react/recommended"
|
|
159
|
-
};
|
|
160
|
-
```
|
|
161
|
-
|
|
162
|
-
#### Next.js Legacy Configuration
|
|
163
|
-
|
|
164
|
-
```js
|
|
165
|
-
module.exports = {
|
|
166
|
-
plugins: ["nextfriday"],
|
|
167
|
-
extends: ["plugin:nextfriday/nextjs"], // or "plugin:nextfriday/nextjs/recommended"
|
|
168
|
-
};
|
|
169
|
-
```
|
|
145
|
+
> **Note:** This plugin requires ESLint 9+ and only supports the flat config format. Legacy `.eslintrc` configurations are not supported.
|
|
170
146
|
|
|
171
147
|
## Rules
|
|
172
148
|
|
|
@@ -225,7 +201,10 @@ module.exports = {
|
|
|
225
201
|
|
|
226
202
|
| Rule | Description | Fixable |
|
|
227
203
|
| -------------------------------------------------------------------------------------- | ---------------------------------------------------------------- | ------- |
|
|
204
|
+
| [enforce-type-declaration-order](docs/rules/ENFORCE_TYPE_DECLARATION_ORDER.md) | Enforce referenced types are declared after their consumer | ❌ |
|
|
205
|
+
| [no-nested-interface-declaration](docs/rules/NO_NESTED_INTERFACE_DECLARATION.md) | Disallow inline object types in interface/type properties | ❌ |
|
|
228
206
|
| [prefer-named-param-types](docs/rules/PREFER_NAMED_PARAM_TYPES.md) | Enforce named types for function parameters with object types | ❌ |
|
|
207
|
+
| [prefer-inline-literal-union](docs/rules/PREFER_INLINE_LITERAL_UNION.md) | Enforce inlining literal union types for better IDE hover info | ✅ |
|
|
229
208
|
| [prefer-interface-over-inline-types](docs/rules/PREFER_INTERFACE_OVER_INLINE_TYPES.md) | Enforce interface declarations over inline types for React props | ❌ |
|
|
230
209
|
| [sort-type-alphabetically](docs/rules/SORT_TYPE_ALPHABETICALLY.md) | Enforce A-Z sorting of properties within type groups | ✅ |
|
|
231
210
|
| [sort-type-required-first](docs/rules/SORT_TYPE_REQUIRED_FIRST.md) | Enforce required properties before optional in types/interfaces | ✅ |
|
|
@@ -259,14 +238,14 @@ module.exports = {
|
|
|
259
238
|
|
|
260
239
|
| Preset | Severity | Base Rules | JSX Rules | Next.js Rules | Total Rules |
|
|
261
240
|
| -------------------- | -------- | ---------- | --------- | ------------- | ----------- |
|
|
262
|
-
| `base` | warn |
|
|
263
|
-
| `base/recommended` | error |
|
|
264
|
-
| `react` | warn |
|
|
265
|
-
| `react/recommended` | error |
|
|
266
|
-
| `nextjs` | warn |
|
|
267
|
-
| `nextjs/recommended` | error |
|
|
241
|
+
| `base` | warn | 36 | 0 | 0 | 36 |
|
|
242
|
+
| `base/recommended` | error | 36 | 0 | 0 | 36 |
|
|
243
|
+
| `react` | warn | 36 | 14 | 0 | 50 |
|
|
244
|
+
| `react/recommended` | error | 36 | 14 | 0 | 50 |
|
|
245
|
+
| `nextjs` | warn | 36 | 14 | 1 | 51 |
|
|
246
|
+
| `nextjs/recommended` | error | 36 | 14 | 1 | 51 |
|
|
268
247
|
|
|
269
|
-
### Base Configuration Rules (
|
|
248
|
+
### Base Configuration Rules (36 rules)
|
|
270
249
|
|
|
271
250
|
Included in `base`, `base/recommended`, and all other presets:
|
|
272
251
|
|
|
@@ -276,6 +255,7 @@ Included in `base`, `base/recommended`, and all other presets:
|
|
|
276
255
|
- `nextfriday/enforce-hook-naming`
|
|
277
256
|
- `nextfriday/enforce-service-naming`
|
|
278
257
|
- `nextfriday/enforce-sorted-destructuring`
|
|
258
|
+
- `nextfriday/enforce-type-declaration-order`
|
|
279
259
|
- `nextfriday/file-kebab-case`
|
|
280
260
|
- `nextfriday/md-filename-case-restriction`
|
|
281
261
|
- `nextfriday/newline-after-multiline-block`
|
|
@@ -288,6 +268,7 @@ Included in `base`, `base/recommended`, and all other presets:
|
|
|
288
268
|
- `nextfriday/no-inline-nested-object`
|
|
289
269
|
- `nextfriday/no-lazy-identifiers`
|
|
290
270
|
- `nextfriday/no-logic-in-params`
|
|
271
|
+
- `nextfriday/no-nested-interface-declaration`
|
|
291
272
|
- `nextfriday/no-nested-ternary`
|
|
292
273
|
- `nextfriday/no-relative-imports`
|
|
293
274
|
- `nextfriday/no-single-char-variables`
|
|
@@ -296,6 +277,7 @@ Included in `base`, `base/recommended`, and all other presets:
|
|
|
296
277
|
- `nextfriday/prefer-function-declaration`
|
|
297
278
|
- `nextfriday/prefer-guard-clause`
|
|
298
279
|
- `nextfriday/prefer-import-type`
|
|
280
|
+
- `nextfriday/prefer-inline-literal-union`
|
|
299
281
|
- `nextfriday/prefer-named-param-types`
|
|
300
282
|
- `nextfriday/prefer-react-import-types`
|
|
301
283
|
- `nextfriday/require-explicit-return-type`
|
|
@@ -345,6 +327,16 @@ Additionally included in `nextjs`, `nextjs/recommended` only:
|
|
|
345
327
|
- **Clean code practices**: Prevents emoji usage, enforces parameter destructuring, and more
|
|
346
328
|
- **Formatting rules**: Enforces consistent blank lines around multi-line blocks and return statements
|
|
347
329
|
|
|
330
|
+
## Agent Skill
|
|
331
|
+
|
|
332
|
+
This plugin ships with an [Agent Skill](https://github.com/anthropics/skills) that teaches AI coding assistants (Claude Code, Cursor, etc.) all 51 rules so they generate compliant code from the start.
|
|
333
|
+
|
|
334
|
+
```bash
|
|
335
|
+
npx skills add next-friday/eslint-plugin-nextfriday --skill eslint-plugin-nextfriday
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
Once installed, AI assistants will automatically follow the naming, code style, type, JSX, import, and formatting patterns enforced by this plugin — reducing lint errors to zero.
|
|
339
|
+
|
|
348
340
|
## Need Help?
|
|
349
341
|
|
|
350
342
|
If you encounter any issues or have questions:
|
|
@@ -354,4 +346,4 @@ If you encounter any issues or have questions:
|
|
|
354
346
|
|
|
355
347
|
## License
|
|
356
348
|
|
|
357
|
-
MIT
|
|
349
|
+
MIT
|
|
@@ -8,9 +8,11 @@ This rule enforces that boolean variables and parameters use a descriptive prefi
|
|
|
8
8
|
|
|
9
9
|
**Recommended prefixes:** `is`, `has`, `should`, `can`, `did`, `will`, `was`, `are`, `does`, `had`
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
## Examples
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
### Incorrect
|
|
14
|
+
|
|
15
|
+
```ts
|
|
14
16
|
const valid = true;
|
|
15
17
|
const user = false;
|
|
16
18
|
const open = true;
|
|
@@ -30,9 +32,9 @@ const fn = (enabled: boolean) => {};
|
|
|
30
32
|
function toggle(active = true) {}
|
|
31
33
|
```
|
|
32
34
|
|
|
33
|
-
|
|
35
|
+
### Correct
|
|
34
36
|
|
|
35
|
-
```
|
|
37
|
+
```ts
|
|
36
38
|
const isValid = true;
|
|
37
39
|
const hasUser = false;
|
|
38
40
|
const isOpen = true;
|
|
@@ -78,24 +80,12 @@ The rule identifies boolean variables and parameters by:
|
|
|
78
80
|
| `does` | Action capability | `doesExist`, `doesMatch`, `doesContain` |
|
|
79
81
|
| `had` | Past possession | `hadError`, `hadAccess`, `hadPrevious` |
|
|
80
82
|
|
|
81
|
-
##
|
|
82
|
-
|
|
83
|
-
- **Self-documenting code**: Boolean intent is immediately clear
|
|
84
|
-
- **Reads like English**: `if (isActive)` reads as "if is active"
|
|
85
|
-
- **Reduced ambiguity**: `user = false` vs `hasUser = false` - the latter is clear
|
|
86
|
-
- **Consistent codebase**: Enforces uniform boolean naming across the project
|
|
87
|
-
- **Better code review**: Reviewers can quickly understand boolean logic
|
|
88
|
-
|
|
89
|
-
## When Not To Use
|
|
83
|
+
## When Not To Use It
|
|
90
84
|
|
|
91
85
|
- When working with external APIs that return boolean fields with different naming conventions
|
|
92
86
|
- In mathematical or scientific code where single-letter variables are conventional
|
|
93
87
|
- When interfacing with legacy code that would require extensive refactoring
|
|
94
88
|
|
|
95
|
-
## Configuration
|
|
96
|
-
|
|
97
|
-
This rule has no configuration options.
|
|
98
|
-
|
|
99
89
|
## Related Rules
|
|
100
90
|
|
|
101
91
|
- [no-single-char-variables](./NO_SINGLE_CHAR_VARIABLES.md) - Disallows single character variable names
|
|
@@ -4,19 +4,13 @@ Enforce SCREAMING_SNAKE_CASE for constant primitive values.
|
|
|
4
4
|
|
|
5
5
|
## Rule Details
|
|
6
6
|
|
|
7
|
-
This rule ensures that `const` declarations with primitive values (strings, numbers, booleans, template literals) use SCREAMING_SNAKE_CASE naming convention.
|
|
8
|
-
|
|
9
|
-
### Why?
|
|
10
|
-
|
|
11
|
-
- **Clarity**: SCREAMING_SNAKE_CASE clearly indicates a value is a constant that shouldn't change
|
|
12
|
-
- **Convention**: Follows common JavaScript/TypeScript naming patterns for constants
|
|
13
|
-
- **Readability**: Makes it easy to distinguish constants from regular variables
|
|
7
|
+
This rule ensures that `const` declarations with primitive values (strings, numbers, booleans, template literals) use SCREAMING_SNAKE_CASE naming convention. Objects, arrays, and functions are not checked. Only `const` declarations are checked; `let` and `var` are ignored.
|
|
14
8
|
|
|
15
9
|
## Examples
|
|
16
10
|
|
|
17
|
-
###
|
|
11
|
+
### Incorrect
|
|
18
12
|
|
|
19
|
-
```
|
|
13
|
+
```ts
|
|
20
14
|
const defaultCover = "/images/default.jpg";
|
|
21
15
|
const pageLimit = 10;
|
|
22
16
|
const isEnabled = true;
|
|
@@ -24,9 +18,9 @@ const apiBaseUrl = "https://api.example.com";
|
|
|
24
18
|
const template = `hello world`;
|
|
25
19
|
```
|
|
26
20
|
|
|
27
|
-
###
|
|
21
|
+
### Correct
|
|
28
22
|
|
|
29
|
-
```
|
|
23
|
+
```ts
|
|
30
24
|
const DEFAULT_COVER = "/images/default.jpg";
|
|
31
25
|
const PAGE_LIMIT = 10;
|
|
32
26
|
const IS_ENABLED = true;
|
|
@@ -47,10 +41,3 @@ var pageLimit = 10;
|
|
|
47
41
|
|
|
48
42
|
- If your project uses different naming conventions for constants
|
|
49
43
|
- If you prefer camelCase for all variable declarations
|
|
50
|
-
|
|
51
|
-
## Notes
|
|
52
|
-
|
|
53
|
-
- Only applies to `const` declarations
|
|
54
|
-
- Only applies to primitive values: strings, numbers, booleans, template literals
|
|
55
|
-
- Objects, arrays, and functions are not checked (can use camelCase/PascalCase)
|
|
56
|
-
- `let` and `var` declarations are not checked
|
|
@@ -13,9 +13,9 @@ This rule manages curly braces for `IfStatement` based on visual layout (line br
|
|
|
13
13
|
|
|
14
14
|
## Examples
|
|
15
15
|
|
|
16
|
-
###
|
|
16
|
+
### Incorrect
|
|
17
17
|
|
|
18
|
-
```
|
|
18
|
+
```ts
|
|
19
19
|
// Single-line with braces (BAD)
|
|
20
20
|
if (!data) {
|
|
21
21
|
return [];
|
|
@@ -30,9 +30,9 @@ if (veryLongCondition && anotherCondition) return [];
|
|
|
30
30
|
if (condition) doSomething();
|
|
31
31
|
```
|
|
32
32
|
|
|
33
|
-
###
|
|
33
|
+
### Correct
|
|
34
34
|
|
|
35
|
-
```
|
|
35
|
+
```ts
|
|
36
36
|
// Single-line without braces (GOOD)
|
|
37
37
|
if (!data) return [];
|
|
38
38
|
if (x > 0) doSomething();
|
|
@@ -4,7 +4,7 @@ Enforce `use` prefix for functions in custom hook files (`*.hook.ts`, `*.hooks.t
|
|
|
4
4
|
|
|
5
5
|
## Rule Details
|
|
6
6
|
|
|
7
|
-
This rule ensures that all exported functions in custom hook files follow React's hook naming convention by starting with `use`.
|
|
7
|
+
This rule ensures that all exported functions in custom hook files (`*.hook.ts`, `*.hooks.ts`) follow React's hook naming convention by starting with `use`.
|
|
8
8
|
|
|
9
9
|
### Why?
|
|
10
10
|
|
|
@@ -14,9 +14,9 @@ This rule ensures that all exported functions in custom hook files follow React'
|
|
|
14
14
|
|
|
15
15
|
## Examples
|
|
16
16
|
|
|
17
|
-
###
|
|
17
|
+
### Incorrect
|
|
18
18
|
|
|
19
|
-
```
|
|
19
|
+
```ts
|
|
20
20
|
// search-params.hook.ts
|
|
21
21
|
export function searchParamsHandler() {}
|
|
22
22
|
export default handleSearch;
|
|
@@ -26,9 +26,9 @@ export const authManager = () => {};
|
|
|
26
26
|
export default function customHook() {}
|
|
27
27
|
```
|
|
28
28
|
|
|
29
|
-
###
|
|
29
|
+
### Correct
|
|
30
30
|
|
|
31
|
-
```
|
|
31
|
+
```ts
|
|
32
32
|
// search-params.hook.ts
|
|
33
33
|
export function useSearchParamsHandler() {}
|
|
34
34
|
export default useSearchParamsHandler;
|
|
@@ -42,10 +42,3 @@ export default function useCustomHook() {}
|
|
|
42
42
|
|
|
43
43
|
- If your project uses a different naming convention for hook files
|
|
44
44
|
- If you don't use the `*.hook.ts` or `*.hooks.ts` file naming pattern
|
|
45
|
-
|
|
46
|
-
## Applies To
|
|
47
|
-
|
|
48
|
-
This rule only applies to files matching:
|
|
49
|
-
|
|
50
|
-
- `*.hook.ts`
|
|
51
|
-
- `*.hooks.ts`
|
|
@@ -4,17 +4,11 @@ Enforce `Props` suffix for interfaces and types in component files (`*.tsx`, `*.
|
|
|
4
4
|
|
|
5
5
|
## Rule Details
|
|
6
6
|
|
|
7
|
-
This rule ensures that all interfaces and object type aliases in React component files end with the `Props` suffix
|
|
8
|
-
|
|
9
|
-
### Why?
|
|
10
|
-
|
|
11
|
-
- **Clarity**: Clearly identifies types that represent component props
|
|
12
|
-
- **Consistency**: Standardizes naming across all component files
|
|
13
|
-
- **Convention**: Follows common React/TypeScript naming patterns
|
|
7
|
+
This rule ensures that all interfaces and object type aliases in React component files (`.tsx`, `.jsx`) end with the `Props` suffix. Only interfaces and type aliases with object literal types are checked; union types, function types, and type references are not affected.
|
|
14
8
|
|
|
15
9
|
## Examples
|
|
16
10
|
|
|
17
|
-
###
|
|
11
|
+
### Incorrect
|
|
18
12
|
|
|
19
13
|
```tsx
|
|
20
14
|
// Button.tsx
|
|
@@ -25,7 +19,7 @@ interface Card {
|
|
|
25
19
|
type ButtonType = { disabled: boolean };
|
|
26
20
|
```
|
|
27
21
|
|
|
28
|
-
###
|
|
22
|
+
### Correct
|
|
29
23
|
|
|
30
24
|
```tsx
|
|
31
25
|
// Button.tsx
|
|
@@ -46,15 +40,3 @@ type ButtonState = SomeOtherType;
|
|
|
46
40
|
|
|
47
41
|
- If your project uses different naming conventions for prop types
|
|
48
42
|
- If you have utility types in component files that shouldn't end with `Props`
|
|
49
|
-
|
|
50
|
-
## Applies To
|
|
51
|
-
|
|
52
|
-
This rule only applies to files with extensions:
|
|
53
|
-
|
|
54
|
-
- `.tsx`
|
|
55
|
-
- `.jsx`
|
|
56
|
-
|
|
57
|
-
## Notes
|
|
58
|
-
|
|
59
|
-
- Only interfaces and type aliases with object literal types are checked
|
|
60
|
-
- Union types, function types, and type references are not affected
|
|
@@ -8,7 +8,7 @@ This rule enforces that React component props using named types (interfaces or t
|
|
|
8
8
|
|
|
9
9
|
## Examples
|
|
10
10
|
|
|
11
|
-
###
|
|
11
|
+
### Incorrect
|
|
12
12
|
|
|
13
13
|
```tsx
|
|
14
14
|
interface Props {
|
|
@@ -35,7 +35,7 @@ function Layout(props: LayoutProps) {
|
|
|
35
35
|
}
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
-
###
|
|
38
|
+
### Correct
|
|
39
39
|
|
|
40
40
|
```tsx
|
|
41
41
|
interface Props {
|
|
@@ -77,7 +77,7 @@ const helper = (props: HelperProps) => {
|
|
|
77
77
|
};
|
|
78
78
|
```
|
|
79
79
|
|
|
80
|
-
## When Not To Use
|
|
80
|
+
## When Not To Use It
|
|
81
81
|
|
|
82
82
|
This rule should not be used if:
|
|
83
83
|
|
|
@@ -93,12 +93,3 @@ This rule is fixable using ESLint's `--fix` option. The fixer will automatically
|
|
|
93
93
|
|
|
94
94
|
- [`prefer-interface-over-inline-types`](./PREFER_INTERFACE_OVER_INLINE_TYPES.md) - Enforces interface declarations over inline types
|
|
95
95
|
- [`react-props-destructure`](./REACT_PROPS_DESTRUCTURE.md) - Enforces destructuring props inside component body
|
|
96
|
-
|
|
97
|
-
## Configuration
|
|
98
|
-
|
|
99
|
-
This rule is included in the following configurations:
|
|
100
|
-
|
|
101
|
-
- `react` (warn)
|
|
102
|
-
- `react/recommended` (error)
|
|
103
|
-
- `nextjs` (warn)
|
|
104
|
-
- `nextjs/recommended` (error)
|
|
@@ -4,7 +4,7 @@ Enforce `fetch` prefix for async functions in `*.service.ts` files instead of `g
|
|
|
4
4
|
|
|
5
5
|
## Rule Details
|
|
6
6
|
|
|
7
|
-
This rule ensures consistent naming conventions for service layer functions. In service files, async data-fetching functions should use the `fetch` prefix to clearly indicate they perform network/API calls.
|
|
7
|
+
This rule ensures consistent naming conventions for service layer functions. In `*.service.ts` files, async data-fetching functions should use the `fetch` prefix to clearly indicate they perform network/API calls.
|
|
8
8
|
|
|
9
9
|
### Why?
|
|
10
10
|
|
|
@@ -14,9 +14,9 @@ This rule ensures consistent naming conventions for service layer functions. In
|
|
|
14
14
|
|
|
15
15
|
## Examples
|
|
16
16
|
|
|
17
|
-
###
|
|
17
|
+
### Incorrect
|
|
18
18
|
|
|
19
|
-
```
|
|
19
|
+
```ts
|
|
20
20
|
// article.service.ts
|
|
21
21
|
export async function getArticles() {}
|
|
22
22
|
export async function loadFaq() {}
|
|
@@ -24,9 +24,9 @@ export async function getUserById() {}
|
|
|
24
24
|
export const getUsers = async () => {};
|
|
25
25
|
```
|
|
26
26
|
|
|
27
|
-
###
|
|
27
|
+
### Correct
|
|
28
28
|
|
|
29
|
-
```
|
|
29
|
+
```ts
|
|
30
30
|
// article.service.ts
|
|
31
31
|
export async function fetchArticles() {}
|
|
32
32
|
export async function fetchFaqList() {}
|
|
@@ -46,7 +46,3 @@ export async function deleteComment() {}
|
|
|
46
46
|
|
|
47
47
|
- If your project uses different naming conventions for service functions
|
|
48
48
|
- If you prefer `get`/`load` prefixes for data-fetching operations
|
|
49
|
-
|
|
50
|
-
## Applies To
|
|
51
|
-
|
|
52
|
-
This rule only applies to files matching `*.service.ts`.
|
|
@@ -24,7 +24,7 @@ Properties are sorted in this order:
|
|
|
24
24
|
|
|
25
25
|
## Examples
|
|
26
26
|
|
|
27
|
-
###
|
|
27
|
+
### Incorrect
|
|
28
28
|
|
|
29
29
|
```js
|
|
30
30
|
// Bad: Not sorted alphabetically
|
|
@@ -66,7 +66,7 @@ const { b, a } = foo;
|
|
|
66
66
|
const { duration = 5000, autoplay = false, totalSlides } = options;
|
|
67
67
|
```
|
|
68
68
|
|
|
69
|
-
###
|
|
69
|
+
### Correct
|
|
70
70
|
|
|
71
71
|
```js
|
|
72
72
|
// Good: Alphabetically sorted without defaults
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# enforce-type-declaration-order
|
|
2
|
+
|
|
3
|
+
Enforce that referenced types and interfaces are declared after the type that uses them.
|
|
4
|
+
|
|
5
|
+
## Rule Details
|
|
6
|
+
|
|
7
|
+
This rule enforces a top-down reading order for type declarations. When an interface or type references another locally-declared type, the referenced (dependency) type must appear _after_ the consumer. This ensures the "main" type is read first, with its supporting types following below.
|
|
8
|
+
|
|
9
|
+
### Why?
|
|
10
|
+
|
|
11
|
+
1. **Top-down readability**: The primary type appears first, making it easy to understand the high-level structure before drilling into details
|
|
12
|
+
2. **Consistency**: A uniform ordering convention eliminates debates about where to place types
|
|
13
|
+
3. **Natural flow**: Mirrors how you'd explain a data structure - start with the big picture, then define the parts
|
|
14
|
+
|
|
15
|
+
## Examples
|
|
16
|
+
|
|
17
|
+
### Incorrect
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
// Dependency declared before consumer
|
|
21
|
+
interface Baz {
|
|
22
|
+
baz: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
interface Foo {
|
|
26
|
+
bar: Baz;
|
|
27
|
+
}
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
type Config = {
|
|
32
|
+
theme: string;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
type Props = {
|
|
36
|
+
config: Config;
|
|
37
|
+
};
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Correct
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
// Consumer first, dependency after
|
|
44
|
+
interface Foo {
|
|
45
|
+
bar: Baz;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
interface Baz {
|
|
49
|
+
baz: string;
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
type Props = {
|
|
55
|
+
config: Config;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
type Config = {
|
|
59
|
+
theme: string;
|
|
60
|
+
};
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
// Chain of dependencies in top-down order
|
|
65
|
+
interface Parent {
|
|
66
|
+
child: Child;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
interface Child {
|
|
70
|
+
grandchild: Grandchild;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
interface Grandchild {
|
|
74
|
+
value: string;
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
// External/imported types are ignored (not locally declared)
|
|
80
|
+
interface Props {
|
|
81
|
+
items: ExternalType[];
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## When Not To Use It
|
|
86
|
+
|
|
87
|
+
If you prefer declaring dependency types before the types that reference them (bottom-up order), or if you don't want to enforce any particular declaration order, you can disable this rule.
|
|
@@ -4,13 +4,13 @@ Enforce kebab-case filenames for .ts and .js files.
|
|
|
4
4
|
|
|
5
5
|
## Rule Details
|
|
6
6
|
|
|
7
|
-
This rule enforces that all TypeScript (.ts) and JavaScript (.js) files use kebab-case naming convention for their **filenames**. Kebab-case uses lowercase letters and hyphens to separate words, making filenames more consistent and URL-friendly.
|
|
7
|
+
This rule enforces that all TypeScript (.ts) and JavaScript (.js) files use kebab-case naming convention for their **filenames**. Kebab-case uses lowercase letters and hyphens to separate words, making filenames more consistent and URL-friendly. Single word filenames are considered valid kebab-case.
|
|
8
8
|
|
|
9
|
-
**This rule checks the filename, not the code content.**
|
|
9
|
+
**This rule checks the filename, not the code content.** Only `.ts` and `.js` files are checked; other file types are ignored.
|
|
10
10
|
|
|
11
11
|
## Examples
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
### Incorrect
|
|
14
14
|
|
|
15
15
|
- `MyFile.ts` (PascalCase)
|
|
16
16
|
- `camelCase.js` (camelCase)
|
|
@@ -19,7 +19,7 @@ This rule enforces that all TypeScript (.ts) and JavaScript (.js) files use keba
|
|
|
19
19
|
- `UPPERCASE.ts` (UPPERCASE)
|
|
20
20
|
- `My File.js` (contains spaces)
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
### Correct
|
|
23
23
|
|
|
24
24
|
- `my-file.ts`
|
|
25
25
|
- `kebab-case.js`
|
|
@@ -28,56 +28,6 @@ This rule enforces that all TypeScript (.ts) and JavaScript (.js) files use keba
|
|
|
28
28
|
- `user-service.ts`
|
|
29
29
|
- `api-utils.ts`
|
|
30
30
|
|
|
31
|
-
## Code Examples
|
|
32
|
-
|
|
33
|
-
The content of the file doesn't matter - only the filename is checked:
|
|
34
|
-
|
|
35
|
-
```typescript
|
|
36
|
-
// INCORRECT: File: MyFile.ts (incorrect filename)
|
|
37
|
-
function myFunction() {
|
|
38
|
-
return "Hello World";
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export { myFunction };
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
```typescript
|
|
45
|
-
// CORRECT: File: my-file.ts (correct filename)
|
|
46
|
-
function myFunction() {
|
|
47
|
-
return "Hello World";
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export { myFunction };
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
```javascript
|
|
54
|
-
// INCORRECT: File: UserService.js (incorrect filename)
|
|
55
|
-
class UserService {
|
|
56
|
-
getUser() {
|
|
57
|
-
return {};
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export { UserService };
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
```javascript
|
|
65
|
-
// CORRECT: File: user-service.js (correct filename)
|
|
66
|
-
class UserService {
|
|
67
|
-
getUser() {
|
|
68
|
-
return {};
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export { UserService };
|
|
73
|
-
```
|
|
74
|
-
|
|
75
31
|
## When Not To Use It
|
|
76
32
|
|
|
77
33
|
If your project has established naming conventions that conflict with kebab-case, or if you're working with frameworks that require specific filename patterns, you may want to disable this rule.
|
|
78
|
-
|
|
79
|
-
## Notes
|
|
80
|
-
|
|
81
|
-
- This rule only applies to `.ts` and `.js` files
|
|
82
|
-
- Other file types (`.jsx`, `.tsx`, `.json`, etc.) are ignored
|
|
83
|
-
- Single word filenames are considered valid kebab-case
|
|
@@ -6,9 +6,9 @@ Require empty lines between sibling JSX elements when at least one spans multipl
|
|
|
6
6
|
|
|
7
7
|
This rule enforces empty lines between sibling JSX elements when either element spans multiple lines. This improves visual separation and readability of complex component structures. Single-line elements do not require empty lines between them.
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
## Examples
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
### Incorrect
|
|
12
12
|
|
|
13
13
|
```jsx
|
|
14
14
|
function Dashboard() {
|
|
@@ -37,7 +37,7 @@ function UserProfile() {
|
|
|
37
37
|
}
|
|
38
38
|
```
|
|
39
39
|
|
|
40
|
-
|
|
40
|
+
### Correct
|
|
41
41
|
|
|
42
42
|
Multi-line elements need empty lines between them:
|
|
43
43
|
|
|
@@ -14,7 +14,7 @@ This rule flags inline object literals used directly as JSX prop values. Inline
|
|
|
14
14
|
|
|
15
15
|
## Examples
|
|
16
16
|
|
|
17
|
-
###
|
|
17
|
+
### Incorrect
|
|
18
18
|
|
|
19
19
|
```tsx
|
|
20
20
|
<Component style={{ color: "red" }} />
|
|
@@ -23,7 +23,7 @@ This rule flags inline object literals used directly as JSX prop values. Inline
|
|
|
23
23
|
<div style={{ margin: 0 }} />
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
-
###
|
|
26
|
+
### Correct
|
|
27
27
|
|
|
28
28
|
```tsx
|
|
29
29
|
const style = { color: "red" };
|