123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- 'use strict';
- const normalizeRuleSettings = require('../normalizeRuleSettings');
- const Result = require('postcss/lib/result');
- const rules = require('../rules');
- function checkAgainstRule(options, callback) {
- if (!options)
- throw new Error(
- "checkAgainstRule requires an options object with 'ruleName', 'ruleSettings', and 'root' properties",
- );
- if (!callback) throw new Error('checkAgainstRule requires a callback');
- if (!options.ruleName) throw new Error("checkAgainstRule requires a 'ruleName' option");
- if (!Object.keys(rules).includes(options.ruleName))
- throw new Error(`Rule '${options.ruleName}' does not exist`);
- if (!options.ruleSettings) throw new Error("checkAgainstRule requires a 'ruleSettings' option");
- if (!options.root) throw new Error("checkAgainstRule requires a 'root' option");
- const settings = normalizeRuleSettings(options.ruleSettings, options.ruleName);
- if (!settings) {
- return;
- }
-
- const tmpPostcssResult = new Result();
- rules[options.ruleName](
- settings[0],
- (settings[1]),
- {},
- )(options.root, tmpPostcssResult);
- for (const warning of tmpPostcssResult.warnings()) callback(warning);
- }
- module.exports = (
- checkAgainstRule
- );
|