eslint-plugin-nextfriday 1.6.0 → 1.7.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 +6 -0
- package/README.md +120 -74
- package/docs/rules/BOOLEAN_NAMING_PREFIX.md +102 -0
- package/docs/rules/NO_DIRECT_DATE.md +36 -0
- package/docs/rules/NO_SINGLE_CHAR_VARIABLES.md +108 -0
- package/docs/rules/PREFER_FUNCTION_DECLARATION.md +139 -0
- package/docs/rules/REQUIRE_EXPLICIT_RETURN_TYPE.md +130 -0
- package/lib/index.cjs +673 -217
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +70 -14
- package/lib/index.d.ts +70 -14
- package/lib/index.js +674 -218
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
- package/docs/rules/NO_EXPLICIT_RETURN_TYPE.md +0 -71
|
@@ -1,71 +0,0 @@
|
|
|
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
|