Skip to content

Commit

Permalink
fix(eslint-plugin): [consistent-type-definitions] correct fix for `ex…
Browse files Browse the repository at this point in the history
…port default` (#3899)
  • Loading branch information
rafaelss95 committed Sep 20, 2021
1 parent 806eaac commit ebb33ed
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
13 changes: 13 additions & 0 deletions packages/eslint-plugin/src/rules/consistent-type-definitions.ts
Expand Up @@ -122,6 +122,19 @@ export default util.createRule({
});
}

if (
node.parent?.type ===
AST_NODE_TYPES.ExportDefaultDeclaration
) {
fixes.push(
fixer.removeRange([node.parent.range[0], node.range[0]]),
fixer.insertTextAfter(
node.body,
`\nexport default ${node.id.name}`,
),
);
}

return fixes;
},
});
Expand Down
@@ -1,5 +1,5 @@
import rule from '../../src/rules/consistent-type-definitions';
import { RuleTester, noFormat } from '../RuleTester';
import { noFormat, RuleTester } from '../RuleTester';

const ruleTester = new RuleTester({
parser: '@typescript-eslint/parser',
Expand Down Expand Up @@ -281,5 +281,29 @@ declare global {
},
],
},
{
// https://github.com/typescript-eslint/typescript-eslint/issues/3894
code: `
export default interface Test {
bar(): string;
foo(): number;
}
`,
output: noFormat`
type Test = {
bar(): string;
foo(): number;
}
export default Test
`,
options: ['type'],
errors: [
{
messageId: 'typeOverInterface',
line: 2,
column: 26,
},
],
},
],
});

0 comments on commit ebb33ed

Please sign in to comment.