@adguard/aglint
Version:
Universal adblock filter list linter.
47 lines (44 loc) • 1.43 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 } from '@adguard/agtree';
import { object, number } from 'superstruct';
import { SEVERITY } from '../severity.js';
const DEFAULT_MIN_RULE_LENGTH = 4;
/**
* Rule that checks if a rule is too short
*/
const NoShortRules = {
meta: {
severity: SEVERITY.error,
config: {
default: {
minLength: DEFAULT_MIN_RULE_LENGTH,
},
schema: object({
minLength: number(),
}),
},
},
events: {
onRule: (context) => {
const minRuleLength = context.config.minLength ?? DEFAULT_MIN_RULE_LENGTH;
const ruleText = context.getActualAdblockRuleRaw();
const ruleTextTrimmed = ruleText.trim();
const ruleNode = context.getActualAdblockRuleAst();
if (
// Ignore comment rules
(ruleNode.category === RuleCategory.Cosmetic || ruleNode.category === RuleCategory.Network)
&& ruleTextTrimmed.length < minRuleLength) {
context.report({
message: `Too short rule: '${ruleText}'`,
node: ruleNode,
});
}
},
},
};
export { NoShortRules };