UNPKG

@adguard/aglint

Version:

Universal adblock filter list linter.

42 lines (39 loc) 1.56 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, CosmeticRuleType } from '@adguard/agtree'; import { SEVERITY } from '../severity.js'; import { isUndefined } from '../../utils/type-guards.js'; import { CssTreeParsingContext } from '../helpers/css-tree-types.js'; /** * Rule that checks if all CSS is syntactically valid */ const NoInvalidCssSyntax = { meta: { severity: SEVERITY.error, }, events: { onRule: (context) => { const ast = context.getActualAdblockRuleAst(); if (ast.category !== RuleCategory.Cosmetic) { return; } if (ast.type === CosmeticRuleType.ElementHidingRule) { const rawSelectorList = ast.body.selectorList; context.getCssNode(rawSelectorList, CssTreeParsingContext.SelectorList); } else if (ast.type === CosmeticRuleType.CssInjectionRule) { const rawSelectorList = ast.body.selectorList; context.getCssNode(rawSelectorList, CssTreeParsingContext.SelectorList); const rawDeclarationList = ast.body.declarationList; if (ast.body.remove !== true && !isUndefined(rawDeclarationList)) { context.getCssNode(rawDeclarationList, CssTreeParsingContext.DeclarationList); } } }, }, }; export { NoInvalidCssSyntax };