From ce25c450fc8561557af73c97bd9111f53dc8bb95 Mon Sep 17 00:00:00 2001 From: dalaoshu Date: Sat, 19 Oct 2024 22:09:37 +0800 Subject: [PATCH] fix(linter): panic in `disable-directives` (#6677) closes #6670 --- crates/oxc_linter/src/disable_directives.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/crates/oxc_linter/src/disable_directives.rs b/crates/oxc_linter/src/disable_directives.rs index 812229f1919b6..3f8ffe115b2f6 100644 --- a/crates/oxc_linter/src/disable_directives.rs +++ b/crates/oxc_linter/src/disable_directives.rs @@ -134,10 +134,10 @@ impl<'a> DisableDirectivesBuilder<'a> { // `eslint-disable-line` else if let Some(text) = text.strip_prefix("-line") { // Get the span between the preceding newline to this comment - let start = source_text[..=comment.span.start as usize] + let start = source_text[..comment.span.start as usize] .lines() .next_back() - .map_or(0, |line| comment.span.start - (line.len() as u32 - 1)); + .map_or(0, |line| comment.span.start - line.len() as u32); let stop = comment.span.start; // `eslint-disable-line` @@ -430,7 +430,8 @@ fn test() { format!(" /* {prefix}-disable , ,no-debugger, , */ debugger; - ") + "), + format!("debugger;//…{prefix}-disable-line") ]; let fail = vec![