🌐 AI搜索 & 代理 主页
Skip to content

Commit 55ebb8b

Browse files
committed
test(linter): add test for disable_for_this_section fix (#14240)
tests from #14214 got closed because #14228 got merged first
1 parent e6118fa commit 55ebb8b

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

crates/oxc_linter/src/lsp.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,50 @@ mod test {
300300
offset_to_position(&Rope::from_str("foo"), 100, "foo");
301301
}
302302

303+
#[test]
304+
fn disable_for_section_js_file() {
305+
let source = "console.log('hello');";
306+
let rope = Rope::from_str(source);
307+
let fix = super::disable_for_this_section("no-console", 0, &rope, source);
308+
309+
assert_eq!(fix.content, "// oxlint-disable no-console\n");
310+
assert_eq!(fix.span.start.line, 0);
311+
assert_eq!(fix.span.start.character, 0);
312+
}
313+
314+
#[test]
315+
fn disable_for_section_after_lf() {
316+
let source = "<script>\nconsole.log('hello');";
317+
let rope = Rope::from_str(source);
318+
let fix = super::disable_for_this_section("no-console", 8, &rope, source);
319+
320+
assert_eq!(fix.content, "// oxlint-disable no-console\n");
321+
assert_eq!(fix.span.start.line, 1);
322+
assert_eq!(fix.span.start.character, 0);
323+
}
324+
325+
#[test]
326+
fn disable_for_section_after_crlf() {
327+
let source = "<script>\r\nconsole.log('hello');";
328+
let rope = Rope::from_str(source);
329+
let fix = super::disable_for_this_section("no-console", 8, &rope, source);
330+
331+
assert_eq!(fix.content, "// oxlint-disable no-console\n");
332+
assert_eq!(fix.span.start.line, 1);
333+
assert_eq!(fix.span.start.character, 0);
334+
}
335+
336+
#[test]
337+
fn disable_for_section_mid_line() {
338+
let source = "const x = 5;";
339+
let rope = Rope::from_str(source);
340+
let fix = super::disable_for_this_section("no-unused-vars", 6, &rope, source);
341+
342+
assert_eq!(fix.content, "\n// oxlint-disable no-unused-vars\n");
343+
assert_eq!(fix.span.start.line, 0);
344+
assert_eq!(fix.span.start.character, 6);
345+
}
346+
303347
fn assert_position(source: &str, offset: u32, expected: (u32, u32)) {
304348
let position = offset_to_position(&Rope::from_str(source), offset, source);
305349
assert_eq!(position.line, expected.0);

0 commit comments

Comments
 (0)