Skip to content

Commit 2a121f0

Browse files
Copilotsapphi-red
andcommitted
Fix lint errors in sourcemap test
- Collapse nested if statements with let-chaining - Use inline format args in assert messages - Replace redundant closure with method reference Co-authored-by: sapphi-red <49056869+sapphi-red@users.noreply.github.com> Co-authored-by: sapphi-red <49056869+sapphi-red@users.noreply.github.com>
1 parent 4b6e0de commit 2a121f0

File tree

1 file changed

+24
-31
lines changed

1 file changed

+24
-31
lines changed

crates/oxc_codegen/tests/integration/sourcemap.rs

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -63,37 +63,30 @@ fn no_invalid_tokens_beyond_source() {
6363
if let Some(ref map) = result.map {
6464
// Verify all tokens have source positions within bounds
6565
for token in map.get_tokens() {
66-
if let Some(source_id) = token.get_source_id() {
67-
if let Some(content) = map.get_source_content(source_id) {
68-
let src_line = token.get_src_line() as usize;
69-
let src_col = token.get_src_col() as usize;
70-
71-
// Split source into lines
72-
let lines: Vec<&str> = content.split('\n').collect();
73-
74-
// Verify line is within bounds
75-
assert!(
76-
src_line < lines.len(),
77-
"Invalid token: line {} is beyond source line count {} for source '{}'",
78-
src_line,
79-
lines.len(),
80-
source_text
81-
);
82-
83-
// Verify column is within line bounds (UTF-16 column count)
84-
let line_content = lines[src_line];
85-
let line_len_utf16: usize =
86-
line_content.chars().map(|c| c.len_utf16()).sum();
87-
88-
assert!(
89-
src_col < line_len_utf16,
90-
"Invalid token: column {} is beyond line length {} for line '{}' in source '{}'",
91-
src_col,
92-
line_len_utf16,
93-
line_content,
94-
source_text
95-
);
96-
}
66+
if let Some(source_id) = token.get_source_id()
67+
&& let Some(content) = map.get_source_content(source_id)
68+
{
69+
let src_line = token.get_src_line() as usize;
70+
let src_col = token.get_src_col() as usize;
71+
72+
// Split source into lines
73+
let lines: Vec<&str> = content.split('\n').collect();
74+
75+
// Verify line is within bounds
76+
assert!(
77+
src_line < lines.len(),
78+
"Invalid token: line {src_line} is beyond source line count {} for source '{source_text}'",
79+
lines.len(),
80+
);
81+
82+
// Verify column is within line bounds (UTF-16 column count)
83+
let line_content = lines[src_line];
84+
let line_len_utf16: usize = line_content.chars().map(char::len_utf16).sum();
85+
86+
assert!(
87+
src_col < line_len_utf16,
88+
"Invalid token: column {src_col} is beyond line length {line_len_utf16} for line '{line_content}' in source '{source_text}'",
89+
);
9790
}
9891
}
9992
}

0 commit comments

Comments
 (0)