Skip to content

Commit 6551dfe

Browse files
committed
refactor(semantic): pass &str instead of Cow (#7972)
As suggested by clippy...
1 parent d4d7bc0 commit 6551dfe

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

crates/oxc_semantic/src/checker/typescript.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,11 @@ pub fn check_ts_type_parameter_declaration(
2626
}
2727
}
2828
/// '?' at the end of a type is not valid TypeScript syntax. Did you mean to write 'number | null | undefined'?(17019)
29-
#[allow(clippy::needless_pass_by_value)]
3029
fn jsdoc_type_in_annotation(
3130
modifier: char,
3231
is_start: bool,
3332
span: Span,
34-
suggested_type: Cow<str>,
33+
suggested_type: &str,
3534
) -> OxcDiagnostic {
3635
let (code, start_or_end) = if is_start { ("17020", "start") } else { ("17019", "end") };
3736

@@ -58,13 +57,19 @@ pub fn check_ts_type_annotation(annotation: &TSTypeAnnotation<'_>, ctx: &Semanti
5857
span_with_illegal_modifier.shrink_right(1)
5958
};
6059

60+
let suggestion = &ctx.source_text[valid_type_span];
6161
let suggestion = if modifier == '?' {
62-
Cow::Owned(format!("{} | null | undefined", &ctx.source_text[valid_type_span]))
62+
Cow::Owned(format!("{suggestion} | null | undefined"))
6363
} else {
64-
Cow::Borrowed(&ctx.source_text[valid_type_span])
64+
Cow::Borrowed(suggestion)
6565
};
6666

67-
ctx.error(jsdoc_type_in_annotation(modifier, is_start, span_with_illegal_modifier, suggestion));
67+
ctx.error(jsdoc_type_in_annotation(
68+
modifier,
69+
is_start,
70+
span_with_illegal_modifier,
71+
&suggestion,
72+
));
6873
}
6974

7075
/// Initializers are not allowed in ambient contexts. ts(1039)

0 commit comments

Comments
 (0)