From d5c10257ee854e89db4dde5782c8c0d834c89714 Mon Sep 17 00:00:00 2001 From: Yusuke Tanaka Date: Mon, 21 Sep 2020 23:13:03 +0900 Subject: [PATCH 1/2] doc(explicit-function-return-type): add description of `allowDirectConstAssertionInArrowFunctions` --- .../rules/explicit-function-return-type.md | 19 +++++++++++++++++++ 1 file changed, 19 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 3cafe4224eb8..8bb265c6e78a 100644 --- a/packages/eslint-plugin/docs/rules/explicit-function-return-type.md +++ b/packages/eslint-plugin/docs/rules/explicit-function-return-type.md @@ -69,6 +69,8 @@ type Options = { allowTypedFunctionExpressions?: boolean; // if true, functions immediately returning another function expression will not be checked allowHigherOrderFunctions?: boolean; + // if true, arrow functions immediately returning a `as const` value will not be checked + allowDirectConstAssertionInArrowFunctions?: boolean; // if true, concise arrow functions that start with the void keyword will not be checked allowConciseArrowFunctionExpressionsStartingWithVoid?: boolean; }; @@ -77,6 +79,7 @@ const defaults = { allowExpressions: false, allowTypedFunctionExpressions: true, allowHigherOrderFunctions: true, + allowDirectConstAssertionInArrowFunctions: true, allowConciseArrowFunctionExpressionsStartingWithVoid: true, }; ``` @@ -201,6 +204,22 @@ function fn() { } ``` +### `allowDirectConstAssertionInArrowFunctions` + +Examples of **incorrect** code for this rule with `{ allowDirectConstAssertionInArrowFunctions: true }`: + +```ts +const func = (value: number) => ({ type: "X", value } as any); +const func = (value: number) => ({ type: "X", value } as Action); +``` + +Examples of **correct** code for this rule with `{ allowDirectConstAssertionInArrowFunctions: true }`: + +```ts +const func = (value: number) => ({ foo: "bar", value } as const); +const func = () => x as const; +``` + ### `allowConciseArrowFunctionExpressionsStartingWithVoid` Examples of **incorrect** code for this rule with `{ allowConciseArrowFunctionExpressionsStartingWithVoid: true }`: From d72a1563133f56aedd8649becea5f74a390e72ac Mon Sep 17 00:00:00 2001 From: Yusuke Tanaka Date: Mon, 21 Sep 2020 23:42:39 +0900 Subject: [PATCH 2/2] docs(eslint-plugin): apply format --- .../docs/rules/explicit-function-return-type.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 8bb265c6e78a..9e5b4c841bf2 100644 --- a/packages/eslint-plugin/docs/rules/explicit-function-return-type.md +++ b/packages/eslint-plugin/docs/rules/explicit-function-return-type.md @@ -209,14 +209,14 @@ function fn() { Examples of **incorrect** code for this rule with `{ allowDirectConstAssertionInArrowFunctions: true }`: ```ts -const func = (value: number) => ({ type: "X", value } as any); -const func = (value: number) => ({ type: "X", value } as Action); +const func = (value: number) => ({ type: 'X', value } as any); +const func = (value: number) => ({ type: 'X', value } as Action); ``` Examples of **correct** code for this rule with `{ allowDirectConstAssertionInArrowFunctions: true }`: ```ts -const func = (value: number) => ({ foo: "bar", value } as const); +const func = (value: number) => ({ foo: 'bar', value } as const); const func = () => x as const; ```