fix(linter): panic in disable-directives (#6677)

closes #6670
This commit is contained in:
dalaoshu 2024-10-19 22:09:37 +08:00 committed by GitHub
parent 002289b4b1
commit ce25c450fc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -134,10 +134,10 @@ impl<'a> DisableDirectivesBuilder<'a> {
// `eslint-disable-line` // `eslint-disable-line`
else if let Some(text) = text.strip_prefix("-line") { else if let Some(text) = text.strip_prefix("-line") {
// Get the span between the preceding newline to this comment // 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() .lines()
.next_back() .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; let stop = comment.span.start;
// `eslint-disable-line` // `eslint-disable-line`
@ -430,7 +430,8 @@ fn test() {
format!(" format!("
/* {prefix}-disable , ,no-debugger, , */ /* {prefix}-disable , ,no-debugger, , */
debugger; debugger;
") "),
format!("debugger;//…{prefix}-disable-line")
]; ];
let fail = vec![ let fail = vec![