diff --git a/packages/eslint-plugin/src/util/explicitReturnTypeUtils.ts b/packages/eslint-plugin/src/util/explicitReturnTypeUtils.ts index 1cfc834c1c1b..2604e6185cc0 100644 --- a/packages/eslint-plugin/src/util/explicitReturnTypeUtils.ts +++ b/packages/eslint-plugin/src/util/explicitReturnTypeUtils.ts @@ -337,15 +337,12 @@ function ancestorHasReturnType(node: FunctionNode): boolean { // const x: Foo = () => {}; // Assume that a typed variable types the function expression case AST_NODE_TYPES.VariableDeclarator: - if (ancestor.id.typeAnnotation) { - return true; - } - break; + return !!ancestor.id.typeAnnotation; + case AST_NODE_TYPES.PropertyDefinition: - if (ancestor.typeAnnotation) { - return true; - } - break; + return !!ancestor.typeAnnotation; + case AST_NODE_TYPES.ExpressionStatement: + return false; } ancestor = ancestor.parent; diff --git a/packages/eslint-plugin/tests/rules/explicit-function-return-type.test.ts b/packages/eslint-plugin/tests/rules/explicit-function-return-type.test.ts index 2036927e0ca9..7556cee3ce77 100644 --- a/packages/eslint-plugin/tests/rules/explicit-function-return-type.test.ts +++ b/packages/eslint-plugin/tests/rules/explicit-function-return-type.test.ts @@ -1016,6 +1016,74 @@ class Foo { }, { code: ` +function foo(): any { + const bar = () => () => console.log('aa'); +} + `, + options: [ + { + allowTypedFunctionExpressions: true, + }, + ], + errors: [ + { + messageId: 'missingReturnType', + line: 3, + endLine: 3, + column: 24, + endColumn: 26, + }, + ], + }, + { + code: ` +let anyValue: any; +function foo(): any { + anyValue = () => () => console.log('aa'); +} + `, + options: [ + { + allowTypedFunctionExpressions: true, + }, + ], + errors: [ + { + messageId: 'missingReturnType', + line: 4, + endLine: 4, + column: 23, + endColumn: 25, + }, + ], + }, + { + code: ` +class Foo { + foo(): any { + const bar = () => () => { + return console.log('foo'); + }; + } +} + `, + options: [ + { + allowTypedFunctionExpressions: true, + }, + ], + errors: [ + { + messageId: 'missingReturnType', + line: 4, + endLine: 4, + column: 26, + endColumn: 28, + }, + ], + }, + { + code: ` var funcExpr = function () { return 'test'; }; @@ -1171,6 +1239,31 @@ const x: Foo = { }, ], }, + { + code: ` +function foo(): any { + class Foo { + foo = () => () => { + return console.log('foo'); + }; + } +} + `, + options: [ + { + allowTypedFunctionExpressions: true, + }, + ], + errors: [ + { + messageId: 'missingReturnType', + line: 4, + endLine: 4, + column: 20, + endColumn: 22, + }, + ], + }, { code: '() => () => {};', options: [{ allowHigherOrderFunctions: true }], diff --git a/packages/website/src/components/editor/LoadedEditor.tsx b/packages/website/src/components/editor/LoadedEditor.tsx index 01434408db7d..6dab67a39278 100644 --- a/packages/website/src/components/editor/LoadedEditor.tsx +++ b/packages/website/src/components/editor/LoadedEditor.tsx @@ -135,14 +135,14 @@ export const LoadedEditor: React.FC = ({ monaco.editor.setModelMarkers(model, 'eslint', diagnostics); updateMarkers(); }); - return () => disposable(); + return (): void => disposable(); }, [webLinter, monaco, codeActions, updateMarkers]); useEffect(() => { const disposable = webLinter.onParse((uri, model) => { onASTChange(model); }); - return () => disposable(); + return (): void => disposable(); }, [webLinter, onASTChange]); useEffect(() => { @@ -178,7 +178,7 @@ export const LoadedEditor: React.FC = ({ 'typescript', createProvideCodeActions(codeActions), ); - return () => disposable.dispose(); + return (): void => disposable.dispose(); }, [codeActions, monaco]); useEffect(() => { @@ -191,7 +191,9 @@ export const LoadedEditor: React.FC = ({ } } }); - return () => disposable.dispose(); + return (): void => { + disposable.dispose(); + }; }, [editor, tabs.eslintrc]); useEffect(() => { @@ -204,7 +206,7 @@ export const LoadedEditor: React.FC = ({ } }, 150), ); - return () => disposable.dispose(); + return (): void => disposable.dispose(); }, [onSelect, editor, tabs.code]); useEffect(() => { @@ -227,7 +229,7 @@ export const LoadedEditor: React.FC = ({ } }, }); - return () => disposable.dispose(); + return (): void => disposable.dispose(); }, [editor, monaco, webLinter]); useEffect(() => { @@ -243,7 +245,7 @@ export const LoadedEditor: React.FC = ({ }), ]; - return () => { + return (): void => { closable.forEach(c => c.close()); }; }, [system, onChange]); @@ -255,14 +257,14 @@ export const LoadedEditor: React.FC = ({ system.writeFile(model.uri.path, model.getValue()); } }); - return () => disposable.dispose(); + return (): void => disposable.dispose(); }, [editor, system]); useEffect(() => { const disposable = monaco.editor.onDidChangeMarkers(() => { updateMarkers(); }); - return () => disposable.dispose(); + return (): void => disposable.dispose(); }, [monaco.editor, updateMarkers]); const resize = useMemo(() => { diff --git a/packages/website/src/hooks/useMediaQuery.ts b/packages/website/src/hooks/useMediaQuery.ts index a092478ac882..422570aee8ef 100644 --- a/packages/website/src/hooks/useMediaQuery.ts +++ b/packages/website/src/hooks/useMediaQuery.ts @@ -29,7 +29,7 @@ const useMediaQuery = (mediaQuery: string): boolean => { } documentChangeHandler(); - return () => { + return (): void => { try { mediaQueryList.removeEventListener('change', documentChangeHandler); } catch {