Skip to content

Commit 3c9e73d

Browse files
[autofix.ci] apply automated fixes
1 parent 7430758 commit 3c9e73d

File tree

1 file changed

+34
-51
lines changed

1 file changed

+34
-51
lines changed

crates/oxc_linter/src/rules/typescript/prefer_function_type.rs

Lines changed: 34 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,7 @@ fn check_member(member: &TSSignature, node: &AstNode<'_>, ctx: &LintContext<'_>)
158158
}
159159
}
160160

161-
let has_comments =
162-
ctx.has_comments_between(interface_decl.span);
161+
let has_comments = ctx.has_comments_between(interface_decl.span);
163162

164163
if has_comments {
165164
let comments = ctx
@@ -192,11 +191,7 @@ fn check_member(member: &TSSignature, node: &AstNode<'_>, ctx: &LintContext<'_>)
192191
format!(
193192
"{}{}{} = {};",
194193
comments_text,
195-
if is_parent_exported {
196-
"export type "
197-
} else {
198-
"type "
199-
},
194+
if is_parent_exported { "export type " } else { "type " },
200195
&interface_decl.id.name,
201196
&suggestion
202197
),
@@ -220,37 +215,37 @@ fn check_member(member: &TSSignature, node: &AstNode<'_>, ctx: &LintContext<'_>)
220215
}
221216
}
222217

223-
AstKind::TSTypeAnnotation(ts_type_annotation) => match &ts_type_annotation
224-
.type_annotation
225-
{
226-
TSType::TSUnionType(union_type) => {
227-
union_type.types.iter().for_each(|ts_type| {
228-
if let TSType::TSTypeLiteral(literal) = ts_type {
229-
ctx.diagnostic_with_fix(
230-
prefer_function_type_diagnostic(&suggestion, decl.span),
231-
|fixer| {
232-
fixer
233-
.replace(literal.span, format!("({suggestion})"))
234-
.with_message(CONVERT_TO_FUNCTION_TYPE)
235-
},
236-
);
237-
}
238-
});
239-
}
218+
AstKind::TSTypeAnnotation(ts_type_annotation) => {
219+
match &ts_type_annotation.type_annotation {
220+
TSType::TSUnionType(union_type) => {
221+
union_type.types.iter().for_each(|ts_type| {
222+
if let TSType::TSTypeLiteral(literal) = ts_type {
223+
ctx.diagnostic_with_fix(
224+
prefer_function_type_diagnostic(&suggestion, decl.span),
225+
|fixer| {
226+
fixer
227+
.replace(literal.span, format!("({suggestion})"))
228+
.with_message(CONVERT_TO_FUNCTION_TYPE)
229+
},
230+
);
231+
}
232+
});
233+
}
240234

241-
TSType::TSTypeLiteral(literal) => ctx.diagnostic_with_fix(
242-
prefer_function_type_diagnostic(&suggestion, decl.span),
243-
|fixer| {
244-
fixer
245-
.replace(literal.span, suggestion)
246-
.with_message(CONVERT_TO_FUNCTION_TYPE)
247-
},
248-
),
235+
TSType::TSTypeLiteral(literal) => ctx.diagnostic_with_fix(
236+
prefer_function_type_diagnostic(&suggestion, decl.span),
237+
|fixer| {
238+
fixer
239+
.replace(literal.span, suggestion)
240+
.with_message(CONVERT_TO_FUNCTION_TYPE)
241+
},
242+
),
249243

250-
_ => {
251-
ctx.diagnostic(prefer_function_type_diagnostic(&suggestion, decl.span));
244+
_ => {
245+
ctx.diagnostic(prefer_function_type_diagnostic(&suggestion, decl.span));
246+
}
252247
}
253-
},
248+
}
254249

255250
AstKind::TSTypeAliasDeclaration(ts_type_alias_decl) => {
256251
match &ts_type_alias_decl.type_annotation {
@@ -264,16 +259,10 @@ fn check_member(member: &TSSignature, node: &AstNode<'_>, ctx: &LintContext<'_>)
264259
return;
265260
}
266261
ctx.diagnostic_with_fix(
267-
prefer_function_type_diagnostic(
268-
&suggestion,
269-
decl.span,
270-
),
262+
prefer_function_type_diagnostic(&suggestion, decl.span),
271263
|fixer| {
272264
fixer
273-
.replace(
274-
literal.span,
275-
format!("({suggestion})"),
276-
)
265+
.replace(literal.span, format!("({suggestion})"))
277266
.with_message(CONVERT_TO_FUNCTION_TYPE)
278267
},
279268
);
@@ -290,16 +279,10 @@ fn check_member(member: &TSSignature, node: &AstNode<'_>, ctx: &LintContext<'_>)
290279
return;
291280
}
292281
ctx.diagnostic_with_fix(
293-
prefer_function_type_diagnostic(
294-
&suggestion,
295-
decl.span,
296-
),
282+
prefer_function_type_diagnostic(&suggestion, decl.span),
297283
|fixer| {
298284
fixer
299-
.replace(
300-
literal.span,
301-
format!("({suggestion})"),
302-
)
285+
.replace(literal.span, format!("({suggestion})"))
303286
.with_message(CONVERT_TO_FUNCTION_TYPE)
304287
},
305288
);

0 commit comments

Comments
 (0)