Skip to content

Commit

Permalink
fix(eslint-plugin): no-empty-interface autofix (#1865)
Browse files Browse the repository at this point in the history
Resolves: #1864
  • Loading branch information
G r e y committed Apr 8, 2020
1 parent 5832a86 commit 829a2f7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
17 changes: 11 additions & 6 deletions packages/eslint-plugin/src/rules/no-empty-interface.ts
Expand Up @@ -61,13 +61,18 @@ export default util.createRule<Options, MessageIds>({
context.report({
node: node.id,
messageId: 'noEmptyWithSuper',
fix: fixer =>
fixer.replaceText(
fix: fixer => {
let typeParam = '';
if (node.typeParameters) {
typeParam = sourceCode.getText(node.typeParameters);
}
return fixer.replaceText(
node,
`type ${sourceCode.getText(node.id)} = ${sourceCode.getText(
extend[0],
)}`,
),
`type ${sourceCode.getText(
node.id,
)}${typeParam} = ${sourceCode.getText(extend[0])}`,
);
},
});
}
}
Expand Down
15 changes: 15 additions & 0 deletions packages/eslint-plugin/tests/rules/no-empty-interface.test.ts
Expand Up @@ -133,5 +133,20 @@ type Foo = R
},
],
},
{
code: `
interface Foo<T> extends Bar<T> {}
`,
output: noFormat`
type Foo<T> = Bar<T>
`,
errors: [
{
messageId: 'noEmptyWithSuper',
line: 2,
column: 11,
},
],
},
],
});

0 comments on commit 829a2f7

Please sign in to comment.