8000 fix(eslint-plugin): [explicit-function-return-type] Fix allowExpressions ignoring default exports by Svish · Pull Request #831 · typescript-eslint/typescript-eslint · GitHub
[go: up one dir, main page]

Skip to content

fix(eslint-plugin): [explicit-function-return-type] Fix allowExpressions ignoring default exports #831

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions packages/eslint-plugin/docs/rules/explicit-function-return-type.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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