fix(linter): fix false positives for generics in no-unexpected-multiline (#6039)

- follow-up to https://github.com/oxc-project/oxc/pull/6031
This commit is contained in:
camchenry 2024-09-24 18:10:01 +00:00
parent 1f92d61097
commit 09a24cd9f1

View file

@ -116,7 +116,13 @@ impl Rule for NoUnexpectedMultiline {
return;
}
let span = Span::new(call_expr.callee.span().end, call_expr.span.end);
let start = if let Some(generics) = &call_expr.type_parameters {
generics.span.end
} else {
call_expr.callee.span().end
};
let span = Span::new(start, call_expr.span.end);
if let Some(open_paren_pos) = has_newline_before(ctx, span, b'(') {
let paren_span = Span::sized(span.start + open_paren_pos, 1);
@ -337,6 +343,13 @@ fn test() {
"class C { field1\n*gen() {} }", // { "ecmaVersion": 2022 },
"class C { field1 = () => {}\n[field2]; }", // { "ecmaVersion": 2022 },
"class C { field1 = () => {}\n*gen() {} }", // { "ecmaVersion": 2022 }
"const foo = bar<{
a: string
b: number
}>();",
"const foo = bar<{
[key: string | number]: string
}>();",
];
let fail = vec![