From ae6c3b28e000c51c5627b8689336c42eb13934bb Mon Sep 17 00:00:00 2001 From: ssube Date: Fri, 15 Nov 2019 21:14:28 -0600 Subject: [PATCH] lint: simplify rule selector logic --- src/rule/index.ts | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/src/rule/index.ts b/src/rule/index.ts index d24bac1..f375ef4 100644 --- a/src/rule/index.ts +++ b/src/rule/index.ts @@ -174,29 +174,35 @@ export async function resolveRules(rules: Array, selector: RuleSelector): const activeRules = new Set(); for (const r of rules) { - if (selector.excludeLevel.includes(r.level)) { - continue; - } - - if (selector.excludeName.includes(r.name)) { - continue; - } - - const excludedTags = intersection(selector.excludeTag, r.tags); - if (excludedTags.length > 0) { - continue; - } + let active = false; if (selector.includeLevel.includes(r.level)) { - activeRules.add(r); + active = true; } if (selector.includeName.includes(r.name)) { - activeRules.add(r); + active = true; } const includedTags = intersection(selector.includeTag, r.tags); if (includedTags.length > 0) { + active = true; + } + + if (selector.excludeLevel.includes(r.level)) { + active = false; + } + + if (selector.excludeName.includes(r.name)) { + active = false; + } + + const excludedTags = intersection(selector.excludeTag, r.tags); + if (excludedTags.length > 0) { + active = false; + } + + if (active) { activeRules.add(r); } }