Skip to content

Commit ebbcc01

Browse files
Svishbradzacher
authored andcommitted
fix(eslint-plugin): [efrt] flag default export w/allowExpressions (#831)
BREAKING: the rule didn't previously flag default exports with this option
1 parent 42b3013 commit ebbcc01

File tree

3 files changed

+45
-11
lines changed

3 files changed

+45
-11
lines changed

packages/eslint-plugin/docs/rules/explicit-function-return-type.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ Examples of **incorrect** code for this rule with `{ allowExpressions: true }`:
8484

8585
```ts
8686
function test() {}
87+
88+
const fn = () => {};
89+
90+
export default () => {};
8791
```
8892

8993
Examples of **correct** code for this rule with `{ allowExpressions: true }`:
@@ -155,24 +159,20 @@ functionWithObjectArg({
155159
Examples of **incorrect** code for this rule with `{ allowHigherOrderFunctions: true }`:
156160

157161
```ts
158-
var arrowFn = (x: number) => (y: number) => x + y;
162+
var arrowFn = () => () => {};
159163

160-
function fn(x: number) {
161-
return function(y: number) {
162-
return x + y;
163-
};
164+
function fn() {
165+
return function() {};
164166
}
165167
```
166168

167169
Examples of **correct** code for this rule with `{ allowHigherOrderFunctions: true }`:
168170

169171
```ts
170-
var arrowFn = (x: number) => (y: number): number => x + y;
172+
var arrowFn = () => (): void => {};
171173

172-
function fn(x: number) {
173-
return function(y: number): number {
174-
return x + y;
175-
};
174+
function fn() {
175+
return function(): void {};
176176
}
177177
```
178178

packages/eslint-plugin/src/rules/explicit-function-return-type.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,8 @@ export default util.createRule<Options, MessageIds>({
256256
if (
257257
options.allowExpressions &&
258258
node.parent.type !== AST_NODE_TYPES.VariableDeclarator &&
259-
node.parent.type !== AST_NODE_TYPES.MethodDefinition
259+
node.parent.type !== AST_NODE_TYPES.MethodDefinition &&
260+
node.parent.type !== AST_NODE_TYPES.ExportDefaultDeclaration
260261
) {
261262
return;
262263
}

packages/eslint-plugin/tests/rules/explicit-function-return-type.test.ts

+33
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,15 @@ class Test {
9090
},
9191
],
9292
},
93+
{
94+
filename: 'test.ts',
95+
code: `export default (): void => {}`,
96+
options: [
97+
{
98+
allowExpressions: true,
99+
},
100+
],
101+
},
93102
{
94103
filename: 'test.ts',
95104
code: `
@@ -417,6 +426,30 @@ function test() {
417426
},
418427
],
419428
},
429+
{
430+
filename: 'test.ts',
431+
code: 'export default () => {};',
432+
options: [{ allowExpressions: true }],
433+
errors: [
434+
{
435+
messageId: 'missingReturnType',
436+
line: 1,
437+
column: 16,
438+
},
439+
],
440+
},
441+
{
442+
filename: 'test.ts',
443+
code: 'export default function() {};',
444+
options: [{ allowExpressions: true }],
445+
errors: [
446+
{
447+
messageId: 'missingReturnType',
448+
line: 1,
449+
column: 16,
450+
},
451+
],
452+
},
420453
{
421454
filename: 'test.ts',
422455
code: "var arrowFn = () => 'test';",

0 commit comments

Comments
 (0)