Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions crates/oxc_linter/src/rules/eslint/curly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,8 +391,16 @@ fn is_lexical_declaration(node: &Statement) -> bool {

#[expect(clippy::cast_possible_truncation)]
fn get_next_char_offset(span: Span, ctx: &LintContext) -> Option<u32> {
let next_char = ctx.source_text()[(span.end as usize)..].chars().next();
next_char.map(|c| span.end + c.len_utf8() as u32)
let src = ctx.source_text();
let start = span.end as usize;

if let Some(tail) = src.get(start..) {
if tail.starts_with("\r\n") || tail.starts_with("\n\r") {
return Some(span.end + 2);
}
}

src[start..].chars().next().map(|c| span.end + c.len_utf8() as u32)
}

#[expect(clippy::cast_possible_truncation)] // for `as i32`
Expand Down Expand Up @@ -801,6 +809,26 @@ fn test() {
"if (a) while (cond) for (;;) for (key in obj) { if (b) foo(); } else bar();",
Some(serde_json::json!(["multi"])),
),
(
" const isIterable = (obj: any) : obj is Iterable<IgnoreRule> => {
if (obj === null) return false;
else if (typeof obj === 'string') return false;
else return typeof value[Symbol.iterator] === 'function';
};",
Some(serde_json::json!(["multi"])),
),
(
"const isIterable = (obj: any): obj is Iterable<IgnoreRule> => {\r\n if (obj === null) return false;\r\n else if (typeof obj === 'string') return false;\r\n else return typeof value[Symbol.iterator] === 'function';\r\n};\r\n",
Some(serde_json::json!(["multi-line"])),
),
(
" const isIterable = (obj: any) : obj is Iterable<IgnoreRule> => {
if (obj === null) return false;
else if (typeof obj === 'string') return false;
else return typeof value[Symbol.iterator] === 'function';
};",
Some(serde_json::json!(["multi"])),
),
];

let fail = vec![
Expand Down
Loading