Skip to content

Commit

Permalink
fix(eslint-plugin): [explicit-module-boundary-types] check allowNames…
Browse files Browse the repository at this point in the history
… on function declarations and property methods (#3051)
  • Loading branch information
a-tarasyuk committed Feb 13, 2021
1 parent 792623f commit 0ade469
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 4 deletions.
Expand Up @@ -224,14 +224,18 @@ export default util.createRule<Options, MessageIds>({
return false;
}

if (node.type === AST_NODE_TYPES.VariableDeclarator) {
if (
node.type === AST_NODE_TYPES.VariableDeclarator ||
node.type === AST_NODE_TYPES.FunctionDeclaration
) {
return (
node.id.type === AST_NODE_TYPES.Identifier &&
node.id?.type === AST_NODE_TYPES.Identifier &&
options.allowedNames.includes(node.id.name)
);
} else if (
node.type === AST_NODE_TYPES.MethodDefinition ||
node.type === AST_NODE_TYPES.TSAbstractMethodDefinition
node.type === AST_NODE_TYPES.TSAbstractMethodDefinition ||
(node.type === AST_NODE_TYPES.Property && node.method)
) {
if (
node.key.type === AST_NODE_TYPES.Literal &&
Expand Down Expand Up @@ -481,7 +485,7 @@ export default util.createRule<Options, MessageIds>({
}
checkedFunctions.add(node);

if (isAllowedName(node.parent) || ancestorHasReturnType(node)) {
if (isAllowedName(node) || ancestorHasReturnType(node)) {
return;
}

Expand Down
Expand Up @@ -321,6 +321,23 @@ export const func2 = (value: number) => ({ type: 'X', value });
},
{
code: `
export function func1() {
return 0;
}
export const foo = {
func2() {
return 0;
},
};
`,
options: [
{
allowedNames: ['func1', 'func2'],
},
],
},
{
code: `
export class Test {
get prop() {
return 1;
Expand Down Expand Up @@ -1798,5 +1815,38 @@ export function foo(...[a]: any): void {}
},
],
},
{
code: `
export function func1() {
return 0;
}
export const foo = {
func2() {
return 0;
},
};
`,
options: [
{
allowedNames: [],
},
],
errors: [
{
messageId: 'missingReturnType',
line: 2,
endLine: 2,
column: 8,
endColumn: 24,
},
{
messageId: 'missingReturnType',
line: 6,
endLine: 6,
column: 3,
endColumn: 10,
},
],
},
],
});

0 comments on commit 0ade469

Please sign in to comment.