UNPKG

@adguard/aglint

Version:

Universal adblock filter list linter.

47 lines (44 loc) 1.58 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, CommentRuleType } from '@adguard/agtree'; import { SEVERITY } from '../severity.js'; import { SUPPORTED_PREPROCESSOR_DIRECTIVES } from '../../common/constants.js'; /** * Checks if a preprocessor directive is known * * @param name Preprocessor directive name to check * @returns `true` if the preprocessor directive is known, `false` otherwise */ function isKnownPreProcessorDirective(name) { return SUPPORTED_PREPROCESSOR_DIRECTIVES.has(name); } /** * Rule that checks if a preprocessor directive is known. * * Directives are case-sensitive, so `!#IF` is to be considered as invalid. */ const UnknownPreProcessorDirectives = { meta: { severity: SEVERITY.error, }, events: { onRule: (context) => { // Get actually iterated adblock rule const ast = context.getActualAdblockRuleAst(); // Check if the rule is a preprocessor comment if (ast.category === RuleCategory.Comment && ast.type === CommentRuleType.PreProcessorCommentRule) { if (!isKnownPreProcessorDirective(ast.name.value)) { context.report({ message: `Unknown preprocessor directive "${ast.name.value}"`, node: ast.name, }); } } }, }, }; export { UnknownPreProcessorDirectives };