Skip to content
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

fix(eslint-plugin): [explicit-module-boundary-types] fix false positives #1490

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 17 additions & 0 deletions packages/eslint-plugin/src/rules/explicit-module-boundary-types.ts
Expand Up @@ -211,6 +211,7 @@ export default util.createRule<Options, MessageIds>({
}

function isUnexported(node: TSESTree.Node | undefined): boolean {
let isReturnedValue = false;
while (node) {
if (
node.type === AST_NODE_TYPES.ExportDefaultDeclaration ||
Expand All @@ -220,6 +221,22 @@ export default util.createRule<Options, MessageIds>({
return false;
}

if (node.type === AST_NODE_TYPES.ReturnStatement) {
isReturnedValue = true;
}

if (
node.type === AST_NODE_TYPES.ArrowFunctionExpression ||
node.type === AST_NODE_TYPES.FunctionDeclaration ||
node.type === AST_NODE_TYPES.FunctionExpression
) {
isReturnedValue = false;
}

if (node.type === AST_NODE_TYPES.BlockStatement && !isReturnedValue) {
return true;
}

node = node.parent;
}

Expand Down
Expand Up @@ -72,6 +72,39 @@ export class Test {
{
filename: 'test.ts',
code: `
export function test(): void {
nested();
return;

function nested() {}
}
`,
},
{
filename: 'test.ts',
code: `
export function test(): string {
const nested = () => 'value';
return nested();
}
`,
},
{
filename: 'test.ts',
code: `
export function test(): string {
class Nested {
public method() {
return 'value';
}
}
return new Nested().method();
}
`,
},
{
filename: 'test.ts',
code: `
export var arrowFn: Foo = () => 'test';
`,
options: [
Expand Down Expand Up @@ -452,6 +485,26 @@ export class Foo {
},
],
},
{
filename: 'test.ts',
code: 'export default () => true ? (() => {}) : ((): void => {});',
errors: [
{
messageId: 'missingReturnType',
line: 1,
endLine: 1,
column: 16,
endColumn: 21,
},
{
messageId: 'missingReturnType',
line: 1,
endLine: 1,
column: 30,
endColumn: 35,
},
],
},
{
filename: 'test.ts',
code: "export var arrowFn = () => 'test';",
Expand Down