UNPKG

@adguard/aglint

Version:

Universal adblock filter list linter.

49 lines (46 loc) 1.81 kB
/* * AGLint v3.0.0 (build date: Wed, 21 May 2025 13:24:14 GMT) * (c) 2025 AdGuard Software Ltd. * Released under the MIT license * https://github.com/AdguardTeam/AGLint#readme */ import { RuleCategory } from '@adguard/agtree'; import { SEVERITY } from '../severity.js'; /** * Rule that checks if a network rule contains multiple same modifiers */ const DuplicatedModifiers = { meta: { severity: SEVERITY.error, }, events: { onRule: (context) => { // Get actually iterated adblock rule const ast = context.getActualAdblockRuleAst(); // Check if the rule is a basic network rule if (ast.category === RuleCategory.Network && ast.type === 'NetworkRule') { // Store which modifiers are already present const occurred = new Set(); // This check is only relevant if there are at least two modifiers if (!ast.modifiers || ast.modifiers.children.length < 2) { return; } for (const modifier of ast.modifiers.children) { const name = modifier.name.value; const nameToLowerCase = name.toLowerCase(); if (!occurred.has(nameToLowerCase)) { occurred.add(nameToLowerCase); } else { // Report if a modifier is occurring more than once context.report({ message: `The modifier "${name}" is used multiple times, but it should be used only once`, node: modifier, }); } } } }, }, }; export { DuplicatedModifiers };