Skip to content
This repository was archived by the owner on Mar 7, 2025. It is now read-only.

Commit aa5b2df

Browse files
committed
Add rule @typescript-eslint/explicit-function-return-type
1 parent db35be8 commit aa5b2df

File tree

2 files changed

+65
-1
lines changed

2 files changed

+65
-1
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import type { RuleConfig } from '../rule-config';
2+
3+
/**
4+
* Option.
5+
*/
6+
export type ExplicitFunctionReturnTypeOption = {
7+
/**
8+
* If `true`, only functions which are part of a declaration will be checked.
9+
*
10+
* @default false
11+
*/
12+
allowExpressions?: boolean;
13+
/**
14+
* If `true`, type annotations are also allowed on the variable of a function expression rather than on the function directly.
15+
*
16+
* @default true
17+
*/
18+
allowTypedFunctionExpressions?: boolean;
19+
/**
20+
* If `true`, functions immediately returning another function expression will not be checked.
21+
*
22+
* @default true
23+
*/
24+
allowHigherOrderFunctions?: boolean;
25+
/**
26+
* If `true`, arrow functions immediately returning a `as const` value will not be checked.
27+
*
28+
* @default true
29+
*/
30+
allowDirectConstAssertionInArrowFunctions?: boolean;
31+
/**
32+
* If `true`, concise arrow functions that start with the void keyword will not be checked.
33+
*
34+
* @default false
35+
*/
36+
allowConciseArrowFunctionExpressionsStartingWithVoid?: boolean;
37+
};
38+
39+
/**
40+
* Options.
41+
*/
42+
export type ExplicitFunctionReturnTypeOptions = [ExplicitFunctionReturnTypeOption?];
43+
44+
/**
45+
* Require explicit return types on functions and class methods.
46+
*
47+
* @see [explicit-function-return-type](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/explicit-function-return-type.md)
48+
*/
49+
export type ExplicitFunctionReturnTypeRuleConfig = RuleConfig<ExplicitFunctionReturnTypeOptions>;
50+
51+
/**
52+
* Require explicit return types on functions and class methods.
53+
*
54+
* @see [explicit-function-return-type](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/explicit-function-return-type.md)
55+
*/
56+
export interface ExplicitFunctionReturnTypeRule {
57+
/**
58+
* Require explicit return types on functions and class methods.
59+
*
60+
* @see [explicit-function-return-type](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/explicit-function-return-type.md)
61+
*/
62+
'@typescript-eslint/explicit-function-return-type': ExplicitFunctionReturnTypeRuleConfig;
63+
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { BanTsCommentRule } from './ban-ts-comment';
2+
import type { ExplicitFunctionReturnTypeRule } from './explicit-function-return-type';
23

34
/**
45
* All @typescript-eslint rules.
56
*/
6-
export type TypeScriptEslintRules = BanTsCommentRule;
7+
export type TypeScriptEslintRules = BanTsCommentRule & ExplicitFunctionReturnTypeRule;

0 commit comments

Comments
 (0)