eslint-plugin-nextfriday 0.1.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/LICENSE +21 -0
- package/README.md +179 -0
- package/docs/rules/FILE_KEBAB_CASE.md +75 -0
- package/docs/rules/JSX_PASCAL_CASE.md +69 -0
- package/docs/rules/MD_FILENAME_CASE_RESTRICTION.md +88 -0
- package/docs/rules/NO_EMOJI.md +31 -0
- package/docs/rules/NO_EXPLICIT_RETURN_TYPE.md +71 -0
- package/docs/rules/PREFER_DESTRUCTURING_PARAMS.md +63 -0
- package/docs/rules/PREFER_IMPORT_TYPE.md +85 -0
- package/lib/index.cjs +550 -0
- package/lib/index.cjs.map +1 -0
- package/lib/index.d.cts +62 -0
- package/lib/index.d.ts +62 -0
- package/lib/index.js +511 -0
- package/lib/index.js.map +1 -0
- package/package.json +116 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Next Friday Co., Ltd.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
# eslint-plugin-nextfriday
|
|
2
|
+
|
|
3
|
+
A comprehensive ESLint plugin providing custom rules and configurations for Next Friday development workflows.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install --save-dev eslint-plugin-nextfriday
|
|
9
|
+
# or
|
|
10
|
+
yarn add --dev eslint-plugin-nextfriday
|
|
11
|
+
# or
|
|
12
|
+
pnpm add -D eslint-plugin-nextfriday
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
### Flat Config (ESLint 9+)
|
|
18
|
+
|
|
19
|
+
#### Base Configuration (for pure JS/TS projects)
|
|
20
|
+
|
|
21
|
+
```js
|
|
22
|
+
import nextfriday from "eslint-plugin-nextfriday";
|
|
23
|
+
|
|
24
|
+
export default [nextfriday.configs.base];
|
|
25
|
+
// or use the recommended preset
|
|
26
|
+
export default [nextfriday.configs["base/recommended"]];
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
#### React Configuration
|
|
30
|
+
|
|
31
|
+
```js
|
|
32
|
+
import nextfriday from "eslint-plugin-nextfriday";
|
|
33
|
+
|
|
34
|
+
export default [nextfriday.configs.react];
|
|
35
|
+
// or use the recommended preset
|
|
36
|
+
export default [nextfriday.configs["react/recommended"]];
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
#### Next.js Configuration
|
|
40
|
+
|
|
41
|
+
```js
|
|
42
|
+
import nextfriday from "eslint-plugin-nextfriday";
|
|
43
|
+
|
|
44
|
+
export default [nextfriday.configs.nextjs];
|
|
45
|
+
// or use the recommended preset
|
|
46
|
+
export default [nextfriday.configs["nextjs/recommended"]];
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Manual Configuration
|
|
50
|
+
|
|
51
|
+
If you prefer to configure rules manually:
|
|
52
|
+
|
|
53
|
+
```js
|
|
54
|
+
import nextfriday from "eslint-plugin-nextfriday";
|
|
55
|
+
|
|
56
|
+
export default [
|
|
57
|
+
{
|
|
58
|
+
plugins: {
|
|
59
|
+
nextfriday,
|
|
60
|
+
},
|
|
61
|
+
rules: {
|
|
62
|
+
// Base rules (suitable for all projects)
|
|
63
|
+
"nextfriday/no-emoji": "error",
|
|
64
|
+
"nextfriday/file-kebab-case": "error",
|
|
65
|
+
"nextfriday/md-filename-case-restriction": "error",
|
|
66
|
+
"nextfriday/prefer-destructuring-params": "error",
|
|
67
|
+
"nextfriday/no-explicit-return-type": "error",
|
|
68
|
+
"nextfriday/prefer-import-type": "error",
|
|
69
|
+
// JSX rule (only for React/Next.js projects)
|
|
70
|
+
"nextfriday/jsx-pascal-case": "error",
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
];
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Legacy Config
|
|
77
|
+
|
|
78
|
+
#### Base Configuration
|
|
79
|
+
|
|
80
|
+
```js
|
|
81
|
+
module.exports = {
|
|
82
|
+
plugins: ["nextfriday"],
|
|
83
|
+
extends: ["plugin:nextfriday/base"], // or "plugin:nextfriday/base/recommended"
|
|
84
|
+
};
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
#### React Configuration
|
|
88
|
+
|
|
89
|
+
```js
|
|
90
|
+
module.exports = {
|
|
91
|
+
plugins: ["nextfriday"],
|
|
92
|
+
extends: ["plugin:nextfriday/react"], // or "plugin:nextfriday/react/recommended"
|
|
93
|
+
};
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
#### Next.js Configuration
|
|
97
|
+
|
|
98
|
+
```js
|
|
99
|
+
module.exports = {
|
|
100
|
+
plugins: ["nextfriday"],
|
|
101
|
+
extends: ["plugin:nextfriday/nextjs"], // or "plugin:nextfriday/nextjs/recommended"
|
|
102
|
+
};
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## Rules
|
|
106
|
+
|
|
107
|
+
| Rule | Description | Fixable |
|
|
108
|
+
| -------------------------------------------------------------------------- | ------------------------------------------------------------ | ------- |
|
|
109
|
+
| [no-emoji](docs/rules/NO_EMOJI.md) | Disallow emojis in code | ❌ |
|
|
110
|
+
| [file-kebab-case](docs/rules/FILE_KEBAB_CASE.md) | Enforce kebab-case filenames for .ts and .js files | ❌ |
|
|
111
|
+
| [jsx-pascal-case](docs/rules/JSX_PASCAL_CASE.md) | Enforce PascalCase filenames for .jsx and .tsx files | ❌ |
|
|
112
|
+
| [md-filename-case-restriction](docs/rules/MD_FILENAME_CASE_RESTRICTION.md) | Enforce SNAKE_CASE filenames for .md files | ❌ |
|
|
113
|
+
| [prefer-destructuring-params](docs/rules/PREFER_DESTRUCTURING_PARAMS.md) | Enforce destructuring for functions with multiple parameters | ❌ |
|
|
114
|
+
| [no-explicit-return-type](docs/rules/NO_EXPLICIT_RETURN_TYPE.md) | Disallow explicit return types on functions | ✅ |
|
|
115
|
+
| [prefer-import-type](docs/rules/PREFER_IMPORT_TYPE.md) | Enforce using 'import type' for type-only imports | ✅ |
|
|
116
|
+
|
|
117
|
+
## Configurations
|
|
118
|
+
|
|
119
|
+
### Base Configurations (for pure JS/TS projects)
|
|
120
|
+
|
|
121
|
+
#### `base`
|
|
122
|
+
|
|
123
|
+
Basic configuration without JSX-specific rules:
|
|
124
|
+
|
|
125
|
+
- `nextfriday/no-emoji`: `"error"`
|
|
126
|
+
- `nextfriday/file-kebab-case`: `"error"`
|
|
127
|
+
- `nextfriday/md-filename-case-restriction`: `"error"`
|
|
128
|
+
- `nextfriday/prefer-destructuring-params`: `"error"`
|
|
129
|
+
- `nextfriday/no-explicit-return-type`: `"error"`
|
|
130
|
+
- `nextfriday/prefer-import-type`: `"error"`
|
|
131
|
+
|
|
132
|
+
#### `base/recommended`
|
|
133
|
+
|
|
134
|
+
Same as `base` configuration (recommended preset for pure JS/TS projects).
|
|
135
|
+
|
|
136
|
+
### React Configurations
|
|
137
|
+
|
|
138
|
+
#### `react`
|
|
139
|
+
|
|
140
|
+
Includes all base rules plus React-specific rules:
|
|
141
|
+
|
|
142
|
+
- All base rules above
|
|
143
|
+
- `nextfriday/jsx-pascal-case`: `"error"`
|
|
144
|
+
|
|
145
|
+
#### `react/recommended`
|
|
146
|
+
|
|
147
|
+
Same as `react` configuration (recommended preset for React projects).
|
|
148
|
+
|
|
149
|
+
### Next.js Configurations
|
|
150
|
+
|
|
151
|
+
#### `nextjs`
|
|
152
|
+
|
|
153
|
+
Includes all rules suitable for Next.js projects:
|
|
154
|
+
|
|
155
|
+
- All base rules
|
|
156
|
+
- `nextfriday/jsx-pascal-case`: `"error"`
|
|
157
|
+
|
|
158
|
+
#### `nextjs/recommended`
|
|
159
|
+
|
|
160
|
+
Same as `nextjs` configuration (recommended preset for Next.js projects).
|
|
161
|
+
|
|
162
|
+
## Features
|
|
163
|
+
|
|
164
|
+
- **File naming enforcement**: Ensure consistent file naming conventions across your project
|
|
165
|
+
- **Import optimization**: Automatically suggests better import patterns for TypeScript
|
|
166
|
+
- **Code cleanup**: Helps remove unnecessary explicit type annotations
|
|
167
|
+
- **React component conventions**: Enforces naming standards for JSX/TSX files
|
|
168
|
+
- **Clean code practices**: Prevents emoji usage and enforces parameter destructuring
|
|
169
|
+
|
|
170
|
+
## Need Help?
|
|
171
|
+
|
|
172
|
+
If you encounter any issues or have questions:
|
|
173
|
+
|
|
174
|
+
- Check the [rule documentation](docs/rules) for detailed examples
|
|
175
|
+
- Report bugs or request features at: <https://github.com/next-friday/eslint-plugin-nextfriday/issues>
|
|
176
|
+
|
|
177
|
+
## License
|
|
178
|
+
|
|
179
|
+
MIT - feel free to use this plugin in your projects!
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# file-kebab-case
|
|
2
|
+
|
|
3
|
+
Enforce kebab-case filenames for .ts and .js files.
|
|
4
|
+
|
|
5
|
+
## Rule Details
|
|
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.
|
|
8
|
+
|
|
9
|
+
**This rule checks the filename, not the code content.**
|
|
10
|
+
|
|
11
|
+
## Examples
|
|
12
|
+
|
|
13
|
+
**Incorrect** filenames for this rule:
|
|
14
|
+
|
|
15
|
+
- `MyFile.ts` (PascalCase)
|
|
16
|
+
- `camelCase.js` (camelCase)
|
|
17
|
+
- `PascalCase.ts` (PascalCase)
|
|
18
|
+
- `snake_case.js` (snake_case)
|
|
19
|
+
- `UPPERCASE.ts` (UPPERCASE)
|
|
20
|
+
- `My File.js` (contains spaces)
|
|
21
|
+
|
|
22
|
+
**Correct** filenames for this rule:
|
|
23
|
+
|
|
24
|
+
- `my-file.ts`
|
|
25
|
+
- `kebab-case.js`
|
|
26
|
+
- `single.ts`
|
|
27
|
+
- `file-with-numbers-123.js`
|
|
28
|
+
- `user-service.ts`
|
|
29
|
+
- `api-utils.ts`
|
|
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
|
+
export const myFunction = () => {
|
|
38
|
+
return "Hello World";
|
|
39
|
+
};
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
```typescript
|
|
43
|
+
// CORRECT: File: my-file.ts (correct filename)
|
|
44
|
+
export const myFunction = () => {
|
|
45
|
+
return "Hello World";
|
|
46
|
+
};
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
```javascript
|
|
50
|
+
// INCORRECT: File: UserService.js (incorrect filename)
|
|
51
|
+
class UserService {
|
|
52
|
+
getUser() {
|
|
53
|
+
return {};
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
```javascript
|
|
59
|
+
// CORRECT: File: user-service.js (correct filename)
|
|
60
|
+
class UserService {
|
|
61
|
+
getUser() {
|
|
62
|
+
return {};
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## When Not To Use It
|
|
68
|
+
|
|
69
|
+
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.
|
|
70
|
+
|
|
71
|
+
## Notes
|
|
72
|
+
|
|
73
|
+
- This rule only applies to `.ts` and `.js` files
|
|
74
|
+
- Other file types (`.jsx`, `.tsx`, `.json`, etc.) are ignored
|
|
75
|
+
- Single word filenames are considered valid kebab-case
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# jsx-pascal-case
|
|
2
|
+
|
|
3
|
+
Enforce PascalCase filenames for .jsx and .tsx files.
|
|
4
|
+
|
|
5
|
+
## Rule Details
|
|
6
|
+
|
|
7
|
+
This rule enforces that JSX and TSX files use PascalCase naming convention for their **filenames**. This is a common pattern in React applications where components are typically named with PascalCase.
|
|
8
|
+
|
|
9
|
+
**This rule checks the filename, not the code content.**
|
|
10
|
+
|
|
11
|
+
## Examples
|
|
12
|
+
|
|
13
|
+
**Incorrect** filenames for this rule:
|
|
14
|
+
|
|
15
|
+
- `my-component.jsx` (kebab-case)
|
|
16
|
+
- `userProfile.jsx` (camelCase)
|
|
17
|
+
- `user_profile.tsx` (snake_case)
|
|
18
|
+
- `component.jsx` (lowercase)
|
|
19
|
+
- `MYCOMPONENT.tsx` (UPPERCASE)
|
|
20
|
+
- `My Component.jsx` (contains spaces)
|
|
21
|
+
- `My.Component.tsx` (contains dots)
|
|
22
|
+
|
|
23
|
+
**Correct** filenames for this rule:
|
|
24
|
+
|
|
25
|
+
- `MyComponent.jsx`
|
|
26
|
+
- `UserProfile.tsx`
|
|
27
|
+
- `App.jsx`
|
|
28
|
+
- `LoginForm.tsx`
|
|
29
|
+
- `UserProfile2.jsx` (PascalCase with numbers)
|
|
30
|
+
|
|
31
|
+
## Code Examples
|
|
32
|
+
|
|
33
|
+
The content of the file doesn't matter - only the filename is checked:
|
|
34
|
+
|
|
35
|
+
```jsx
|
|
36
|
+
// INCORRECT: File: my-component.jsx (incorrect filename)
|
|
37
|
+
export default function MyComponent() {
|
|
38
|
+
return <div>Hello</div>;
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
```jsx
|
|
43
|
+
// CORRECT: File: MyComponent.jsx (correct filename)
|
|
44
|
+
export default function MyComponent() {
|
|
45
|
+
return <div>Hello</div>;
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
```tsx
|
|
50
|
+
// INCORRECT: File: user-profile.tsx (incorrect filename)
|
|
51
|
+
export default function UserProfile() {
|
|
52
|
+
return <div>Profile</div>;
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
```tsx
|
|
57
|
+
// CORRECT: File: UserProfile.tsx (correct filename)
|
|
58
|
+
export default function UserProfile() {
|
|
59
|
+
return <div>Profile</div>;
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## When Not To Use
|
|
64
|
+
|
|
65
|
+
If your project uses different naming conventions for JSX/TSX files, you can disable this rule.
|
|
66
|
+
|
|
67
|
+
## Related Rules
|
|
68
|
+
|
|
69
|
+
- [file-kebab-case](./FILE_KEBAB_CASE.md) - For regular TypeScript and JavaScript files
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# md-filename-case-restriction
|
|
2
|
+
|
|
3
|
+
Enforce SNAKE_CASE filenames for .md files.
|
|
4
|
+
|
|
5
|
+
## Rule Details
|
|
6
|
+
|
|
7
|
+
This rule enforces that all Markdown (.md) files use SNAKE_CASE naming convention for their **filenames**. SNAKE_CASE uses UPPERCASE letters and underscores to separate words. This helps maintain consistency for documentation files and ensures they stand out from regular code files.
|
|
8
|
+
|
|
9
|
+
**This rule checks the filename, not the file content.**
|
|
10
|
+
|
|
11
|
+
## Examples
|
|
12
|
+
|
|
13
|
+
**Correct** filenames for this rule:
|
|
14
|
+
|
|
15
|
+
- `README.md` (SNAKE_CASE)
|
|
16
|
+
- `CHANGELOG.md` (SNAKE_CASE)
|
|
17
|
+
- `CONTRIBUTING.md` (SNAKE_CASE)
|
|
18
|
+
- `LICENSE.md` (SNAKE_CASE)
|
|
19
|
+
- `USER_GUIDE.md` (SNAKE_CASE)
|
|
20
|
+
- `INSTALLATION_GUIDE.md` (SNAKE_CASE)
|
|
21
|
+
- `TROUBLESHOOTING_GUIDE.md` (SNAKE_CASE)
|
|
22
|
+
- `GUIDE_2024.md` (SNAKE_CASE with numbers)
|
|
23
|
+
- `LICENSE_MIT.md` (SNAKE_CASE with underscores)
|
|
24
|
+
|
|
25
|
+
**Incorrect** filenames for this rule:
|
|
26
|
+
|
|
27
|
+
- `readme.md` (lowercase)
|
|
28
|
+
- `user-guide.md` (kebab-case)
|
|
29
|
+
- `userGuide.md` (camelCase)
|
|
30
|
+
- `UserGuide.md` (PascalCase)
|
|
31
|
+
- `myREADME.md` (mixed case)
|
|
32
|
+
- `User guide.md` (contains spaces)
|
|
33
|
+
|
|
34
|
+
## Code Examples
|
|
35
|
+
|
|
36
|
+
The content of the file doesn't matter - only the filename is checked:
|
|
37
|
+
|
|
38
|
+
```markdown
|
|
39
|
+
<!-- INCORRECT: File: readme.md (incorrect filename) -->
|
|
40
|
+
|
|
41
|
+
# My Project
|
|
42
|
+
|
|
43
|
+
This is a sample project.
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
```markdown
|
|
47
|
+
<!-- CORRECT: File: README.md (correct filename) -->
|
|
48
|
+
|
|
49
|
+
# My Project
|
|
50
|
+
|
|
51
|
+
This is a sample project.
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
```markdown
|
|
55
|
+
<!-- INCORRECT: File: user-guide.md (incorrect filename) -->
|
|
56
|
+
|
|
57
|
+
# User Guide
|
|
58
|
+
|
|
59
|
+
Follow these steps to get started.
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
```markdown
|
|
63
|
+
<!-- CORRECT: File: USER_GUIDE.md (correct filename) -->
|
|
64
|
+
|
|
65
|
+
# User Guide
|
|
66
|
+
|
|
67
|
+
Follow these steps to get started.
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Valid Patterns
|
|
71
|
+
|
|
72
|
+
### SNAKE_CASE
|
|
73
|
+
|
|
74
|
+
- All letters are UPPERCASE
|
|
75
|
+
- Uses underscores to separate words
|
|
76
|
+
- May contain numbers
|
|
77
|
+
- Examples: `README.md`, `USER_GUIDE.md`, `GUIDE_2024.md`, `LICENSE_MIT.md`
|
|
78
|
+
|
|
79
|
+
## When Not To Use It
|
|
80
|
+
|
|
81
|
+
If your project has established naming conventions for documentation that conflict with this rule, or if you need to maintain compatibility with external tools that expect specific markdown filename patterns, you may want to disable this rule.
|
|
82
|
+
|
|
83
|
+
## Notes
|
|
84
|
+
|
|
85
|
+
- This rule only applies to `.md` files
|
|
86
|
+
- Other file types are ignored
|
|
87
|
+
- Single word filenames must be UPPERCASE (e.g., `README.md`, `LICENSE.md`)
|
|
88
|
+
- Underscores are used to separate words in multi-word filenames
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# no-emoji
|
|
2
|
+
|
|
3
|
+
Disallow emoji characters in source code.
|
|
4
|
+
|
|
5
|
+
## Rule Details
|
|
6
|
+
|
|
7
|
+
This rule prevents the use of emoji characters in JavaScript and TypeScript source code. Emoji characters can cause encoding issues, make code harder to read on certain systems, and may not be supported in all environments.
|
|
8
|
+
|
|
9
|
+
## Examples
|
|
10
|
+
|
|
11
|
+
**Incorrect** code for this rule:
|
|
12
|
+
|
|
13
|
+
```js
|
|
14
|
+
const message = "Hello 🌍 world";
|
|
15
|
+
const greeting = "Hi there! 👋";
|
|
16
|
+
// Comment with emoji 😀
|
|
17
|
+
const celebration = "🎉 Party time! 🎊";
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
**Correct** code for this rule:
|
|
21
|
+
|
|
22
|
+
```js
|
|
23
|
+
const message = "Hello world";
|
|
24
|
+
const greeting = "Hi there!";
|
|
25
|
+
// Comment without emoji
|
|
26
|
+
const celebration = "Party time!";
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## When Not To Use It
|
|
30
|
+
|
|
31
|
+
If your team explicitly wants to allow emoji characters in source code and has no concerns about encoding or compatibility issues, you can disable this rule.
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# no-explicit-return-type
|
|
2
|
+
|
|
3
|
+
Disallow explicit return types on functions.
|
|
4
|
+
|
|
5
|
+
This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).
|
|
6
|
+
|
|
7
|
+
## Rule Details
|
|
8
|
+
|
|
9
|
+
This rule encourages relying on TypeScript's type inference instead of explicitly annotating function return types. TypeScript is generally very good at inferring return types, and explicit annotations can add unnecessary verbosity to your code.
|
|
10
|
+
|
|
11
|
+
**Incorrect** code for this rule:
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
function getName(): string {
|
|
15
|
+
return "John Doe";
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const getAge = (): number => {
|
|
19
|
+
return 25;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
function processUser(): void {
|
|
23
|
+
console.log("Processing user");
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const calculateTotal = (items: Item[]): number => {
|
|
27
|
+
return items.reduce((sum, item) => sum + item.price, 0);
|
|
28
|
+
};
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
**Correct** code for this rule:
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
function getName() {
|
|
35
|
+
return "John Doe"; // TypeScript infers: string
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const getAge = () => {
|
|
39
|
+
return 25; // TypeScript infers: number
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
function processUser() {
|
|
43
|
+
console.log("Processing user"); // TypeScript infers: void
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const calculateTotal = (items: Item[]) => {
|
|
47
|
+
return items.reduce((sum, item) => sum + item.price, 0); // TypeScript infers: number
|
|
48
|
+
};
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Benefits
|
|
52
|
+
|
|
53
|
+
- **Cleaner code**: Reduces visual clutter
|
|
54
|
+
- **Automatic updates**: When implementation changes, return type updates automatically
|
|
55
|
+
- **Trust TypeScript**: Leverages TypeScript's excellent type inference
|
|
56
|
+
- **Consistency**: Encourages a consistent style across the codebase
|
|
57
|
+
|
|
58
|
+
## When Not To Use
|
|
59
|
+
|
|
60
|
+
- When you want to explicitly document the return type for API functions
|
|
61
|
+
- For public library functions where return types serve as documentation
|
|
62
|
+
- When the inferred type is too broad and you want to narrow it
|
|
63
|
+
- In cases where explicit return types improve error messages
|
|
64
|
+
|
|
65
|
+
## Auto-fixing
|
|
66
|
+
|
|
67
|
+
This rule automatically removes explicit return type annotations when run with the `--fix` option.
|
|
68
|
+
|
|
69
|
+
## Related Rules
|
|
70
|
+
|
|
71
|
+
- No related rules
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# prefer-destructuring-params
|
|
2
|
+
|
|
3
|
+
Enforce destructuring for functions with multiple parameters.
|
|
4
|
+
|
|
5
|
+
## Rule Details
|
|
6
|
+
|
|
7
|
+
This rule enforces the use of object destructuring for functions that have multiple parameters. This improves code readability and makes it easier to understand what parameters a function expects.
|
|
8
|
+
|
|
9
|
+
**Incorrect** code for this rule:
|
|
10
|
+
|
|
11
|
+
```javascript
|
|
12
|
+
function createUser(name, email, age, address) {
|
|
13
|
+
// ...
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const processOrder = (orderId, customerId, items, total) => {
|
|
17
|
+
// ...
|
|
18
|
+
};
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
**Correct** code for this rule:
|
|
22
|
+
|
|
23
|
+
```javascript
|
|
24
|
+
function createUser({ name, email, age, address }) {
|
|
25
|
+
// ...
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const processOrder = ({ orderId, customerId, items, total }) => {
|
|
29
|
+
// ...
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
// Single parameter functions are allowed
|
|
33
|
+
function getName(user) {
|
|
34
|
+
return user.name;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Functions with no parameters are allowed
|
|
38
|
+
function getCurrentTime() {
|
|
39
|
+
return new Date();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Functions with already destructured parameters are allowed
|
|
43
|
+
function updateUser({ name, email }, additionalData) {
|
|
44
|
+
// ...
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Benefits
|
|
49
|
+
|
|
50
|
+
- **Improved readability**: It's clear what properties are expected
|
|
51
|
+
- **Better maintainability**: Adding or removing parameters is easier
|
|
52
|
+
- **Self-documenting code**: Parameter names are explicit at the call site
|
|
53
|
+
- **TypeScript benefits**: Better type inference and autocompletion
|
|
54
|
+
|
|
55
|
+
## When Not To Use
|
|
56
|
+
|
|
57
|
+
- If your project prefers traditional parameter lists
|
|
58
|
+
- For performance-critical functions where destructuring overhead matters
|
|
59
|
+
- When dealing with legacy code that can't be easily refactored
|
|
60
|
+
|
|
61
|
+
## Related Rules
|
|
62
|
+
|
|
63
|
+
- No related rules
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# prefer-import-type
|
|
2
|
+
|
|
3
|
+
Enforce using 'import type' for type-only imports.
|
|
4
|
+
|
|
5
|
+
This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).
|
|
6
|
+
|
|
7
|
+
## Rule Details
|
|
8
|
+
|
|
9
|
+
This rule enforces the use of TypeScript's `import type` syntax for imports that are only used for type annotations. This helps with tree-shaking and makes it clear which imports are type-only vs runtime imports.
|
|
10
|
+
|
|
11
|
+
**Incorrect** code for this rule:
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { Component } from "react";
|
|
15
|
+
import { TSESTree } from "@typescript-eslint/utils";
|
|
16
|
+
import { RuleContext } from "@typescript-eslint/utils";
|
|
17
|
+
|
|
18
|
+
interface Props {
|
|
19
|
+
component: Component;
|
|
20
|
+
tree: TSESTree.Node;
|
|
21
|
+
context: RuleContext<string, unknown[]>;
|
|
22
|
+
}
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
**Correct** code for this rule:
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
import type { Component } from "react";
|
|
29
|
+
import type { TSESTree } from "@typescript-eslint/utils";
|
|
30
|
+
import type { RuleContext } from "@typescript-eslint/utils";
|
|
31
|
+
|
|
32
|
+
interface Props {
|
|
33
|
+
component: Component;
|
|
34
|
+
tree: TSESTree.Node;
|
|
35
|
+
context: RuleContext<string, unknown[]>;
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
**Allowed runtime imports:**
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
import React from "react";
|
|
43
|
+
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
44
|
+
import * as utils from "./utils";
|
|
45
|
+
|
|
46
|
+
// Mixed imports are also supported
|
|
47
|
+
import { ESLintUtils, type TSESTree } from "@typescript-eslint/utils";
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Benefits
|
|
51
|
+
|
|
52
|
+
- **Better tree-shaking**: Type-only imports are completely removed from the bundle
|
|
53
|
+
- **Clearer intent**: Makes it obvious which imports are for types vs runtime
|
|
54
|
+
- **Faster compilation**: TypeScript can optimize type-only imports
|
|
55
|
+
- **Bundle size**: Reduces final JavaScript bundle size
|
|
56
|
+
|
|
57
|
+
## Detection Logic
|
|
58
|
+
|
|
59
|
+
The rule identifies type-only imports by checking if:
|
|
60
|
+
|
|
61
|
+
1. The imported identifier starts with an uppercase letter (indicating a type/interface)
|
|
62
|
+
2. It's not a known runtime import like `ESLintUtils` or `RuleTester`
|
|
63
|
+
3. The import is not already using `import type`
|
|
64
|
+
|
|
65
|
+
## Auto-fixing
|
|
66
|
+
|
|
67
|
+
This rule automatically converts regular imports to `import type` when appropriate:
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
// Before
|
|
71
|
+
import { TSESTree } from "@typescript-eslint/utils";
|
|
72
|
+
|
|
73
|
+
// After (auto-fixed)
|
|
74
|
+
import type { TSESTree } from "@typescript-eslint/utils";
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## When Not To Use
|
|
78
|
+
|
|
79
|
+
- If your project doesn't use TypeScript
|
|
80
|
+
- When you prefer to keep all imports as regular imports for consistency
|
|
81
|
+
- If you have specific bundling requirements that don't benefit from type-only imports
|
|
82
|
+
|
|
83
|
+
## Related Rules
|
|
84
|
+
|
|
85
|
+
- [@typescript-eslint/consistent-type-imports](https://typescript-eslint.io/rules/consistent-type-imports/) - Similar rule from typescript-eslint
|