From 7144892a4fa67367ba0d3753db91aa00b2520c7b Mon Sep 17 00:00:00 2001 From: Eran Hirsch Date: Wed, 15 Feb 2023 12:43:48 +0200 Subject: [PATCH] docs: explicit-function-return-type/allowFunctionsWithoutTypeParameters --- .../rules/explicit-function-return-type.md | 32 +++++++++++++++++++ .../rules/explicit-function-return-type.ts | 1 + 2 files changed, 33 insertions(+) diff --git a/packages/eslint-plugin/docs/rules/explicit-function-return-type.md b/packages/eslint-plugin/docs/rules/explicit-function-return-type.md index a5df82f958ab..0d0e476d576c 100644 --- a/packages/eslint-plugin/docs/rules/explicit-function-return-type.md +++ b/packages/eslint-plugin/docs/rules/explicit-function-return-type.md @@ -242,6 +242,38 @@ const log = (message: string) => { var log = (message: string) => void console.log(message); ``` +### `allowFunctionsWithoutTypeParameters` + +Examples of code for this rule with `{ allowFunctionsWithoutTypeParameters: true }`: + + + +#### ❌ Incorrect + +```ts +function foo(t: T) { + return t; +} + +const bar = (t: T) => t; +``` + +#### ✅ Correct + +```ts +function foo(t: T): T { + return t; +} + +const bar = (t: T): T => t; + +const allowedFunction(x: string) { + return x; +} + +const allowedArrow = (x: string) => x; +``` + ### `allowedNames` You may pass function/method names you would like this rule to ignore, like so: diff --git a/packages/eslint-plugin/src/rules/explicit-function-return-type.ts b/packages/eslint-plugin/src/rules/explicit-function-return-type.ts index 254c48a0965c..b19ec1527ec0 100644 --- a/packages/eslint-plugin/src/rules/explicit-function-return-type.ts +++ b/packages/eslint-plugin/src/rules/explicit-function-return-type.ts @@ -93,6 +93,7 @@ export default util.createRule({ allowHigherOrderFunctions: true, allowDirectConstAssertionInArrowFunctions: true, allowConciseArrowFunctionExpressionsStartingWithVoid: false, + allowFunctionsWithoutTypeParameters: false, allowedNames: [], allowIIFEs: false, }, pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy