Skip to content

Commit 64cd060

Browse files
fix(linter): enforce exact matching for disable directives
Co-authored-by: overlookmotel <557937+overlookmotel@users.noreply.github.com>
1 parent 88dd33c commit 64cd060

File tree

2 files changed

+42
-42
lines changed

2 files changed

+42
-42
lines changed

crates/oxc_linter/src/disable_directives.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,10 @@ impl<'a> DisableDirectives<'a> {
143143
// Check if this rule should be disabled
144144
let rule_matches = match interval.val {
145145
DisabledRule::All { .. } => true,
146-
// Our rule name currently does not contain the prefix.
147-
// For example, this will match `@typescript-eslint/no-var-requires` given
148-
// our rule_name is `no-var-requires`.
149-
DisabledRule::Single { rule_name: name, .. } => name.contains(rule_name),
146+
// Use exact matching instead of substring matching to require precise rule names.
147+
// For external plugin rules, this enforces the requirement that disable directives
148+
// must include the full plugin name (e.g., "plugin-name/rule-name").
149+
DisabledRule::Single { rule_name: name, .. } => name == rule_name,
150150
};
151151

152152
if !rule_matches {

napi/oxlint2/test/__snapshots__/e2e.test.ts.snap

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -462,44 +462,44 @@ Finished in Xms on 1 file using X threads."
462462

463463
exports[`oxlint2 CLI > should respect disable directives for custom plugin rules 1`] = `
464464
"
465-
x test-plugin(no-var): Use let or const instead of var
466-
,-[index.js:1:1]
467-
1 | var shouldError = 1;
468-
: ^^^^^^^^^^^^^^^^^^^^
469-
2 |
470-
\`----
471-
472-
x ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\\eslint(no-debugger)]8;;\\: \`debugger\` statement is not allowed
473-
,-[index.js:10:1]
474-
9 | // should trigger an error
475-
10 | debugger;
476-
: ^^^^^^^^^
477-
11 |
478-
\`----
479-
help: Remove the debugger statement
480-
481-
x test-plugin(no-var): Use let or const instead of var
482-
,-[index.js:16:1]
483-
15 | /* oxlint-disable-next-line test-plugin */ // \`test-plugin\` should be \`test-plugin/no-var\`
484-
16 | var incorrectlyDisabled = 4;
485-
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
486-
17 |
487-
\`----
488-
489-
x test-plugin(no-var): Use let or const instead of var
490-
,-[index.js:19:1]
491-
18 | /* oxlint-disable-next-line no-var */ // \`no-var\` should be \`test-plugin/no-var\`
492-
19 | var anotherIncorrectlyDisabled = 4;
493-
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
494-
20 |
495-
\`----
496-
497-
x test-plugin(no-var): Use let or const instead of var
498-
,-[index.js:22:1]
499-
21 | // This var should trigger an error again
500-
22 | var shouldErrorAgain = 3;
501-
: ^^^^^^^^^^^^^^^^^^^^^^^^^
502-
\`----
465+
× eslint(no-debugger): \`debugger\` statement is not allowed
466+
╭─[index.js:10:1]
467+
 9 │ // should trigger an error
468+
10 │ debugger;
469+
· ─────────
470+
11 │
471+
╰────
472+
 help: Remove the debugger statement
473+
474+
× test-plugin(no-var): Use let or const instead of var
475+
╭─[index.js:1:1]
476+
1 │ var shouldError = 1;
477+
· ────────────────────
478+
2 │
479+
╰────
480+
481+
× test-plugin(no-var): Use let or const instead of var
482+
╭─[index.js:16:1]
483+
15 │ /* oxlint-disable-next-line test-plugin */ // \`test-plugin\` should be \`test-plugin/no-var\`
484+
16 │ var incorrectlyDisabled = 4;
485+
· ────────────────────────────
486+
17 │
487+
╰────
488+
489+
× test-plugin(no-var): Use let or const instead of var
490+
╭─[index.js:19:1]
491+
18 │ /* oxlint-disable-next-line no-var */ // \`no-var\` should be \`test-plugin/no-var\`
492+
19 │ var anotherIncorrectlyDisabled = 4;
493+
· ───────────────────────────────────
494+
20 │
495+
╰────
496+
497+
× test-plugin(no-var): Use let or const instead of var
498+
╭─[index.js:22:1]
499+
21 │ // This var should trigger an error again
500+
22 │ var shouldErrorAgain = 3;
501+
· ─────────────────────────
502+
╰────
503503

504504
Found 0 warnings and 5 errors.
505505
Finished in Xms on 1 file using X threads."

0 commit comments

Comments
 (0)