@adguard/aglint
Version:
Universal adblock filter list linter.
39 lines (36 loc) • 1.25 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, DomainUtils } from '@adguard/agtree';
import { SEVERITY } from '../severity.js';
/**
* Rule that checks validity of domains in cosmetic rules
*/
const InvalidDomainList = {
meta: {
severity: SEVERITY.error,
},
events: {
onRule: (context) => {
// Get actually iterated adblock rule
const ast = context.getActualAdblockRuleAst();
// Check if the rule is a cosmetic rule (any cosmetic rule)
if (ast.category === RuleCategory.Cosmetic) {
// Iterate over all domains within the rule
for (const node of ast.domains.children) {
// If the domain is invalid, report it
if (!DomainUtils.isValidDomainOrHostname(node.value)) {
context.report({
message: `Invalid domain "${node.value}"`,
node,
});
}
}
}
},
},
};
export { InvalidDomainList };