Skip to content

Commit

Permalink
chore: minor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
ota-meshi committed Oct 3, 2023
1 parent 82e08b4 commit 9aff13a
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/linter/apply-disable-directives.js
Expand Up @@ -205,7 +205,7 @@ function processUnusedDirectives(allDirectives) {
* @returns {Iterable<Directive>} The used eslint-enable comments
*/
function *collectUsedEnableDirectives(directives) {
const allKey = Symbol("all");
const withoutRuleIdKey = Symbol("withoutRuleId");
const enabledRules = new Map();

for (let index = directives.length - 1; index >= 0; index--) {
Expand Down Expand Up @@ -241,16 +241,16 @@ function *collectUsedEnableDirectives(directives) {
yield enableDirective;
enabledRules.delete(directive.ruleId);
} else {
const allEnabledDirective = enabledRules.get(allKey);
const enabledDirectiveWithoutRuleId = enabledRules.get(withoutRuleIdKey);

if (allEnabledDirective) {
if (enabledDirectiveWithoutRuleId) {

// If encounter `eslint-disable` with ruleId, and there is no `eslint-enable` with the same ruleId in enabledRules,
// mark `eslint-enable` without ruleId as used.
// e.g.
// /* eslint-disable rule-id */ <- current directive
// /* eslint-enable */ <- used
yield allEnabledDirective;
yield enabledDirectiveWithoutRuleId;
}
}
}
Expand All @@ -264,7 +264,7 @@ function *collectUsedEnableDirectives(directives) {
// /* eslint-enable rule-id *// <- unused
// /* eslint-enable */ <- unused
enabledRules.clear();
enabledRules.set(allKey, directive);
enabledRules.set(withoutRuleIdKey, directive);
} else {
enabledRules.set(directive.ruleId, directive);
}
Expand Down

0 comments on commit 9aff13a

Please sign in to comment.