Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(eslint-plugin): [explicit-module-boundary-types] check allowNames on function declarations and property methods #3051

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 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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,
},
],
},
],
});