Skip to content
This repository has been archived by the owner on Jan 28, 2024. It is now read-only.

Commit

Permalink
Merge pull request #3 from StyleShit/fix/non-eslint-comments
Browse files Browse the repository at this point in the history
fix: rule throws error for non `eslint-disable` comments
  • Loading branch information
JoshuaKGoldberg authored Dec 11, 2023
2 parents 182adf7 + 8024e9d commit d369cb0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/rules.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,9 @@ ruleTester.run("rules", rules, {
code: `/* eslint-disable no-shadow, no-var */`,
options: [{ rules: [{ message: "Do not want.", rule: "one-var" }] }],
},
{
code: `/* we-should-never-eslint-disable one-var */`,
options: [{ rules: [{ message: "Do not want.", rule: "one-var" }] }],
},
],
});
4 changes: 2 additions & 2 deletions src/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ export const rules: TSESLint.RuleModule<MessageIds, [Options]> = createRule<
const ruleBans = rules.map(({ message, rule }) => ({
message,
rule,
tester: new RegExp(`eslint-disable(?:-next-line)?.*${rule}`),
tester: new RegExp(`^eslint-disable(?:-next-line)?.*${rule}`),
}));

return {
Program() {
for (const comment of context.sourceCode.getAllComments()) {
for (const ruleBan of ruleBans) {
if (ruleBan.tester.test(comment.value)) {
if (ruleBan.tester.test(comment.value.trim())) {
context.report({
data: {
message: ruleBan.message,
Expand Down

0 comments on commit d369cb0

Please sign in to comment.