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] check allowNames on function declarations and property methods #3051

Merged
merged 2 commits into from Feb 13, 2021
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
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,
},
],
},
],
});