Skip to content

Commit

Permalink
fix(eslint-plugin): [consistent-type-definitions] correct fixer with …
Browse files Browse the repository at this point in the history
…declare keyword (#4334)
  • Loading branch information
armano2 committed Dec 21, 2021
1 parent c3e1834 commit 0cd911a
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
Expand Up @@ -58,7 +58,7 @@ export default util.createRule({
const typeNode = node.typeParameters ?? node.id;
const fixes: TSESLint.RuleFix[] = [];

const firstToken = sourceCode.getFirstToken(node);
const firstToken = sourceCode.getTokenBefore(node.id);
if (firstToken) {
fixes.push(fixer.replaceText(firstToken, 'interface'));
fixes.push(
Expand Down Expand Up @@ -98,7 +98,7 @@ export default util.createRule({
const typeNode = node.typeParameters ?? node.id;
const fixes: TSESLint.RuleFix[] = [];

const firstToken = sourceCode.getFirstToken(node);
const firstToken = sourceCode.getTokenBefore(node.id);
if (firstToken) {
fixes.push(fixer.replaceText(firstToken, 'type'));
fixes.push(
Expand Down
Expand Up @@ -305,5 +305,51 @@ export default Test
},
],
},
{
// https://github.com/typescript-eslint/typescript-eslint/issues/4333
code: `
export declare type Test = {
foo: string;
bar: string;
};
`,
output: `
export declare interface Test {
foo: string;
bar: string;
}
`,
options: ['interface'],
errors: [
{
messageId: 'interfaceOverType',
line: 2,
column: 21,
},
],
},
{
// https://github.com/typescript-eslint/typescript-eslint/issues/4333
code: `
export declare interface Test {
foo: string;
bar: string;
}
`,
output: noFormat`
export declare type Test = {
foo: string;
bar: string;
}
`,
options: ['type'],
errors: [
{
messageId: 'typeOverInterface',
line: 2,
column: 26,
},
],
},
],
});

0 comments on commit 0cd911a

Please sign in to comment.