Skip to content

Commit

Permalink
fix(eslint-plugin): [efrt] flag default export w/allowExpressions (#831)
Browse files Browse the repository at this point in the history
BREAKING: the rule didn't previously flag default exports with this option
  • Loading branch information
Svish authored and bradzacher committed Aug 10, 2019
1 parent 42b3013 commit ebbcc01
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 11 deletions.
20 changes: 10 additions & 10 deletions packages/eslint-plugin/docs/rules/explicit-function-return-type.md
Expand Up @@ -84,6 +84,10 @@ Examples of **incorrect** code for this rule with `{ allowExpressions: true }`:

```ts
function test() {}

const fn = () => {};

export default () => {};
```

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

```ts
var arrowFn = (x: number) => (y: number) => x + y;
var arrowFn = () => () => {};

function fn(x: number) {
return function(y: number) {
return x + y;
};
function fn() {
return function() {};
}
```

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

```ts
var arrowFn = (x: number) => (y: number): number => x + y;
var arrowFn = () => (): void => {};

function fn(x: number) {
return function(y: number): number {
return x + y;
};
function fn() {
return function(): void {};
}
```

Expand Down
Expand Up @@ -256,7 +256,8 @@ export default util.createRule<Options, MessageIds>({
if (
options.allowExpressions &&
node.parent.type !== AST_NODE_TYPES.VariableDeclarator &&
node.parent.type !== AST_NODE_TYPES.MethodDefinition
node.parent.type !== AST_NODE_TYPES.MethodDefinition &&
node.parent.type !== AST_NODE_TYPES.ExportDefaultDeclaration
) {
return;
}
Expand Down
Expand Up @@ -90,6 +90,15 @@ class Test {
},
],
},
{
filename: 'test.ts',
code: `export default (): void => {}`,
options: [
{
allowExpressions: true,
},
],
},
{
filename: 'test.ts',
code: `
Expand Down Expand Up @@ -417,6 +426,30 @@ function test() {
},
],
},
{
filename: 'test.ts',
code: 'export default () => {};',
options: [{ allowExpressions: true }],
errors: [
{
messageId: 'missingReturnType',
line: 1,
column: 16,
},
],
},
{
filename: 'test.ts',
code: 'export default function() {};',
options: [{ allowExpressions: true }],
errors: [
{
messageId: 'missingReturnType',
line: 1,
column: 16,
},
],
},
{
filename: 'test.ts',
code: "var arrowFn = () => 'test';",
Expand Down

0 comments on commit ebbcc01

Please sign in to comment.