4 const normalizeRuleSettings = require("../normalizeRuleSettings");
5 const Result = require("postcss/lib/result");
6 const rules = require("../rules");
8 // Useful for third-party code (e.g. plugins) to run a PostCSS Root
9 // against a specific rule and do something with the warnings
10 module.exports = function(
13 ruleSettings: stylelint$configRuleSettings,
16 callback /*: Function*/
20 "checkAgainstRule requires an options object with 'ruleName', 'ruleSettings', and 'root' properties"
22 if (!callback) throw new Error("checkAgainstRule requires a callback");
23 if (!options.ruleName)
24 throw new Error("checkAgainstRule requires a 'ruleName' option");
25 if (!rules[options.ruleName])
26 throw new Error(`Rule '${options.ruleName}' does not exist`);
27 if (!options.ruleSettings)
28 throw new Error("checkAgainstRule requires a 'ruleSettings' option");
30 throw new Error("checkAgainstRule requires a 'root' option");
32 const settings = normalizeRuleSettings(
40 const tmpPostcssResult = new Result();
41 rules[options.ruleName](settings[0], settings[1], {})(
45 tmpPostcssResult.warnings().forEach(callback);