From 034ca9818280f285078468f58cd3b5d9d51ecf3d Mon Sep 17 00:00:00 2001 From: Wei Zhu Date: Thu, 6 Apr 2023 22:46:01 +1000 Subject: [PATCH] fix(linter): fix panic when directive appears at the first line (#264) --- crates/oxc_linter/src/disable_directives.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/oxc_linter/src/disable_directives.rs b/crates/oxc_linter/src/disable_directives.rs index 8a18b46eb..6a4648bff 100644 --- a/crates/oxc_linter/src/disable_directives.rs +++ b/crates/oxc_linter/src/disable_directives.rs @@ -97,7 +97,7 @@ impl<'a, 'b> DisableDirectivesBuilder<'a, 'b> { .lines() .rev() .next() - .map_or(0, |line| span.start - line.len() as u32); + .map_or(0, |line| span.start - (line.len() as u32 - 1)); let stop = span.start; // `eslint-disable-line` @@ -192,7 +192,7 @@ fn test() { // debugger; // ", // To disable all rules on a specific line, use a line or block comment in one of the following formats: - " + "debugger; // eslint-disable-line debugger; // eslint-disable-line // eslint-disable-next-line