Skip to content

Commit ebb33ed

Browse files
authored
fix(eslint-plugin): [consistent-type-definitions] correct fix for export default (typescript-eslint#3899)
1 parent 806eaac commit ebb33ed

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

packages/eslint-plugin/src/rules/consistent-type-definitions.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,19 @@ export default util.createRule({
122122
});
123123
}
124124

125+
if (
126+
node.parent?.type ===
127+
AST_NODE_TYPES.ExportDefaultDeclaration
128+
) {
129+
fixes.push(
130+
fixer.removeRange([node.parent.range[0], node.range[0]]),
131+
fixer.insertTextAfter(
132+
node.body,
133+
`\nexport default ${node.id.name}`,
134+
),
135+
);
136+
}
137+
125138
return fixes;
126139
},
127140
});

packages/eslint-plugin/tests/rules/consistent-type-definitions.test.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import rule from '../../src/rules/consistent-type-definitions';
2-
import { RuleTester, noFormat } from '../RuleTester';
2+
import { noFormat, RuleTester } from '../RuleTester';
33

44
const ruleTester = new RuleTester({
55
parser: '@typescript-eslint/parser',
@@ -281,5 +281,29 @@ declare global {
281281
},
282282
],
283283
},
284+
{
285+
// https://github.com/typescript-eslint/typescript-eslint/issues/3894
286+
code: `
287+
export default interface Test {
288+
bar(): string;
289+
foo(): number;
290+
}
291+
`,
292+
output: noFormat`
293+
type Test = {
294+
bar(): string;
295+
foo(): number;
296+
}
297+
export default Test
298+
`,
299+
options: ['type'],
300+
errors: [
301+
{
302+
messageId: 'typeOverInterface',
303+
line: 2,
304+
column: 26,
305+
},
306+
],
307+
},
284308
],
285309
});

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy