Skip to content

fix(eslint-plugin): [consistent-type-definitions] correct fixer with declare keyword #4334

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 1 commit into from
Dec 21, 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 @@ -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
Original file line number Diff line number Diff line change
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,
},
],
},
],
});