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

feat(eslint-plugin): [adjacent-overload-signatures] check BlockStatement nodes #5998

Merged
merged 3 commits into from Nov 17, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -8,7 +8,8 @@ type RuleNode =
| TSESTree.Program
| TSESTree.TSModuleBlock
| TSESTree.TSTypeLiteral
| TSESTree.TSInterfaceBody;
| TSESTree.TSInterfaceBody
| TSESTree.BlockStatement;
type Member =
| TSESTree.ClassElement
| TSESTree.ProgramStatement
Expand Down Expand Up @@ -121,6 +122,7 @@ export default util.createRule({
case AST_NODE_TYPES.Program:
case AST_NODE_TYPES.TSModuleBlock:
case AST_NODE_TYPES.TSInterfaceBody:
case AST_NODE_TYPES.BlockStatement:
return node.body;

case AST_NODE_TYPES.TSTypeLiteral:
Expand Down Expand Up @@ -172,6 +174,7 @@ export default util.createRule({
TSModuleBlock: checkBodyForOverloadMethods,
TSTypeLiteral: checkBodyForOverloadMethods,
TSInterfaceBody: checkBodyForOverloadMethods,
BlockStatement: checkBodyForOverloadMethods,
};
},
});
Expand Up @@ -250,12 +250,64 @@ class Test {

'#private'(): void;
'#private'(arg: number): void {}
}
`,
// block statement
`
function wrap() {
function foo(s: string);
function foo(n: number);
function foo(sn: string | number) {}
}
`,
`
if (true) {
function foo(s: string);
function foo(n: number);
function foo(sn: string | number) {}
}
`,
],
invalid: [
{
code: `
function wrap() {
function foo(s: string);
function foo(n: number);
type bar = number;
function foo(sn: string | number) {}
}
`,
errors: [
{
messageId: 'adjacentSignature',
data: { name: 'foo' },
line: 6,
column: 3,
},
],
},
{
code: `
if (true) {
function foo(s: string);
function foo(n: number);
let a = 1;
function foo(sn: string | number) {}
foo(a);
}
`,
errors: [
{
messageId: 'adjacentSignature',
data: { name: 'foo' },
line: 6,
column: 3,
},
],
},
lsdsjy marked this conversation as resolved.
Show resolved Hide resolved
{
code: `
export function foo(s: string);
export function foo(n: number);
export function bar(): void {}
Expand Down