Skip to content

Commit c211d32

Browse files
authored
fix(linter): fix whitespace handling in disable directives (#13083)
- fixes(#13071) - Replace ' ' with char::is_whitespace for better whitespace detection
1 parent a0ccada commit c211d32

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

crates/oxc_linter/src/disable_directives.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,9 +359,9 @@ impl<'a> DisableDirectivesBuilder<'a> {
359359
}
360360
continue;
361361
}
362-
// Remaining text should start with a space, else it's probably a typo of the correct syntax.
362+
// Remaining text should start with a whitespace character, else it's probably a typo of the correct syntax.
363363
// Like `eslint-disable-lext-nine` where `text` is `-lext-nine`, or directive is `eslint-disablefoo`
364-
else if text.starts_with(' ') {
364+
else if text.starts_with(char::is_whitespace) {
365365
// `eslint-disable rule-name1, rule-name2`
366366
let mut rules = vec![];
367367
Self::get_rule_names(text, rule_name_start, |rule_name, name_span| {
@@ -639,6 +639,14 @@ fn test() {
639639
640640
/* \t {prefix}-disable-next-line no-debugger */
641641
debugger;
642+
"
643+
),
644+
// Handles whitespace character before rule name in comment
645+
format!(
646+
"/*{prefix}-disable
647+
no-debugger
648+
*/
649+
debugger;
642650
"
643651
),
644652
// Extra commas

0 commit comments

Comments
 (0)