mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 12:19:15 +00:00
refactor(semantic): pass &str instead of Cow (#7972)
As suggested by clippy...
This commit is contained in:
parent
d4d7bc08d3
commit
6551dfef5c
1 changed files with 10 additions and 5 deletions
|
|
@ -26,12 +26,11 @@ pub fn check_ts_type_parameter_declaration(
|
|||
}
|
||||
}
|
||||
/// '?' at the end of a type is not valid TypeScript syntax. Did you mean to write 'number | null | undefined'?(17019)
|
||||
#[allow(clippy::needless_pass_by_value)]
|
||||
fn jsdoc_type_in_annotation(
|
||||
modifier: char,
|
||||
is_start: bool,
|
||||
span: Span,
|
||||
suggested_type: Cow<str>,
|
||||
suggested_type: &str,
|
||||
) -> OxcDiagnostic {
|
||||
let (code, start_or_end) = if is_start { ("17020", "start") } else { ("17019", "end") };
|
||||
|
||||
|
|
@ -58,13 +57,19 @@ pub fn check_ts_type_annotation(annotation: &TSTypeAnnotation<'_>, ctx: &Semanti
|
|||
span_with_illegal_modifier.shrink_right(1)
|
||||
};
|
||||
|
||||
let suggestion = &ctx.source_text[valid_type_span];
|
||||
let suggestion = if modifier == '?' {
|
||||
Cow::Owned(format!("{} | null | undefined", &ctx.source_text[valid_type_span]))
|
||||
Cow::Owned(format!("{suggestion} | null | undefined"))
|
||||
} else {
|
||||
Cow::Borrowed(&ctx.source_text[valid_type_span])
|
||||
Cow::Borrowed(suggestion)
|
||||
};
|
||||
|
||||
ctx.error(jsdoc_type_in_annotation(modifier, is_start, span_with_illegal_modifier, suggestion));
|
||||
ctx.error(jsdoc_type_in_annotation(
|
||||
modifier,
|
||||
is_start,
|
||||
span_with_illegal_modifier,
|
||||
&suggestion,
|
||||
));
|
||||
}
|
||||
|
||||
/// Initializers are not allowed in ambient contexts. ts(1039)
|
||||
|
|
|
|||
Loading…
Reference in a new issue