@adguard/aglint
Version:
Universal adblock filter list linter.
49 lines (46 loc) • 1.8 kB
JavaScript
/*
* 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, CommentRuleType } from '@adguard/agtree';
import { SEVERITY } from '../severity.js';
/**
* Rule that checks if hints are duplicated within the same comment rule.
*/
const DuplicatedHints = {
meta: {
severity: SEVERITY.warn,
},
events: {
onRule: (context) => {
// Get actually iterated adblock rule
const ast = context.getActualAdblockRuleAst();
if (ast.category === RuleCategory.Comment && ast.type === CommentRuleType.HintCommentRule) {
// Only makes sense to check this, if there are at least two hints within the comment
if (ast.children.length < 2) {
return;
}
// Store which hints are already present
const occurred = new Set();
// Iterate over all hints within the comment rule
for (const hint of ast.children) {
const name = hint.name.value;
const nameToLowerCase = name.toLowerCase();
if (!occurred.has(nameToLowerCase)) {
occurred.add(nameToLowerCase);
}
else {
// Report if a hint is occurring more than once
context.report({
message: `The hint "${name}" is occurring more than once within the same comment rule`,
node: hint,
});
}
}
}
},
},
};
export { DuplicatedHints };