Skip to content
Permalink
Browse files

fix(eslint-plugin): [method-signature-style] correct fixer for overlo…

…ads in an object literal type (#2708)
  • Loading branch information
a-tarasyuk committed Oct 25, 2020
1 parent 66e9c6e commit 0763913c4a0d1061465ae3329704f1a7de4b9326
@@ -118,15 +118,20 @@ export default util.createRule<Options, MessageIds>({
return;
}

const duplicatedKeyMethodNodes: TSESTree.TSMethodSignature[] =
methodNode.parent?.type === AST_NODE_TYPES.TSInterfaceBody
? methodNode.parent.body.filter(
(element): element is TSESTree.TSMethodSignature =>
element.type === AST_NODE_TYPES.TSMethodSignature &&
element !== methodNode &&
getMethodKey(element) === getMethodKey(methodNode),
)
const parent = methodNode.parent;
const members =
parent?.type === AST_NODE_TYPES.TSInterfaceBody
? parent.body
: parent?.type === AST_NODE_TYPES.TSTypeLiteral
? parent.members
: [];

const duplicatedKeyMethodNodes: TSESTree.TSMethodSignature[] = members.filter(
(element): element is TSESTree.TSMethodSignature =>
element.type === AST_NODE_TYPES.TSMethodSignature &&
element !== methodNode &&
getMethodKey(element) === getMethodKey(methodNode),
);
const isParentModule = isNodeParentModuleDeclaration(methodNode);

if (duplicatedKeyMethodNodes.length > 0) {
@@ -371,5 +371,61 @@ interface Foo {
},
],
},
{
code: noFormat`
type Foo = {
foo(): one;
foo(): two;
foo(): three;
}
`,
output: noFormat`
type Foo = {
foo: (() => one) & (() => two) & (() => three);
}
`,
errors: [
{
messageId: 'errorMethod',
line: 3,
},
{
messageId: 'errorMethod',
line: 4,
},
{
messageId: 'errorMethod',
line: 5,
},
],
},
{
code: noFormat`
declare const Foo: {
foo(): one;
foo(): two;
foo(): three;
}
`,
output: noFormat`
declare const Foo: {
foo: (() => one) & (() => two) & (() => three);
}
`,
errors: [
{
messageId: 'errorMethod',
line: 3,
},
{
messageId: 'errorMethod',
line: 4,
},
{
messageId: 'errorMethod',
line: 5,
},
],
},
],
});

0 comments on commit 0763913

Please sign in to comment.
You can’t perform that action at this time.