fix(linter) fix bug in fixer for prefer-function-type when interface is exported (#5122)

part of https://github.com/oxc-project/oxc/issues/5103
This commit is contained in:
camc314 2024-08-23 12:45:22 +00:00
parent f7958c4cc2
commit b7ba9c01a1

View file

@ -206,8 +206,10 @@ fn check_member(member: &TSSignature, node: &AstNode<'_>, ctx: &LintContext<'_>)
Fix::new(
format!(
"type {} = {};",
&interface_decl.id.name, &suggestion
"{} {} = {};",
if is_parent_exported { "export type" } else { "type" },
&interface_decl.id.name,
&suggestion
),
Span::new(node_start, node_end),
)
@ -718,6 +720,11 @@ type X = {} & (() => void);
",
None,
),
(
"export interface AnyFn { (...args: any[]): any }",
"export type AnyFn = (...args: any[]) => any;",
None,
),
];
Tester::new(PreferFunctionType::NAME, pass, fail).expect_fix(fix).test_and_snapshot();