1 | 'use strict';
|
2 |
|
3 | const normalizeRuleSettings = require('../normalizeRuleSettings');
|
4 | const requireRule = require('../requireRule');
|
5 | const Result = require('postcss/lib/result');
|
6 | const rules = require('../rules');
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | module.exports = function (options, callback) {
|
20 | if (!options)
|
21 | throw new Error(
|
22 | "checkAgainstRule requires an options object with 'ruleName', 'ruleSettings', and 'root' properties",
|
23 | );
|
24 |
|
25 | if (!callback) throw new Error('checkAgainstRule requires a callback');
|
26 |
|
27 | if (!options.ruleName) throw new Error("checkAgainstRule requires a 'ruleName' option");
|
28 |
|
29 | if (!rules.includes(options.ruleName))
|
30 | throw new Error(`Rule '${options.ruleName}' does not exist`);
|
31 |
|
32 | if (!options.ruleSettings) throw new Error("checkAgainstRule requires a 'ruleSettings' option");
|
33 |
|
34 | if (!options.root) throw new Error("checkAgainstRule requires a 'root' option");
|
35 |
|
36 | const settings = normalizeRuleSettings(options.ruleSettings, options.ruleName);
|
37 |
|
38 | if (!settings) {
|
39 | return;
|
40 | }
|
41 |
|
42 | const tmpPostcssResult = new Result();
|
43 |
|
44 | requireRule(options.ruleName)(settings[0], settings[1], {})(options.root, tmpPostcssResult);
|
45 | tmpPostcssResult.warnings().forEach(callback);
|
46 | };
|