1 |
|
2 |
|
3 | 'use strict';
|
4 |
|
5 | const _ = require('lodash');
|
6 | const isStandardSyntaxAtRule = require('../../utils/isStandardSyntaxAtRule');
|
7 | const report = require('../../utils/report');
|
8 | const ruleMessages = require('../../utils/ruleMessages');
|
9 | const validateOptions = require('../../utils/validateOptions');
|
10 |
|
11 | const ruleName = 'at-rule-property-requirelist';
|
12 |
|
13 | const messages = ruleMessages(ruleName, {
|
14 | expected: (property, atRule) => `Expected property "${property}" for at-rule "${atRule}"`,
|
15 | });
|
16 |
|
17 | function rule(primary) {
|
18 | return (root, result) => {
|
19 | const validOptions = validateOptions(result, ruleName, {
|
20 | actual: primary,
|
21 | possible: [_.isObject],
|
22 | });
|
23 |
|
24 | if (!validOptions) {
|
25 | return;
|
26 | }
|
27 |
|
28 | root.walkAtRules((atRule) => {
|
29 | if (!isStandardSyntaxAtRule(atRule)) {
|
30 | return;
|
31 | }
|
32 |
|
33 | const { name, nodes } = atRule;
|
34 | const atRuleName = name.toLowerCase();
|
35 |
|
36 | if (!primary[atRuleName]) {
|
37 | return;
|
38 | }
|
39 |
|
40 | primary[atRuleName].forEach((property) => {
|
41 | const propertyName = property.toLowerCase();
|
42 |
|
43 | const hasProperty = nodes.find(
|
44 | ({ type, prop }) => type === 'decl' && prop.toLowerCase() === propertyName,
|
45 | );
|
46 |
|
47 | if (hasProperty) {
|
48 | return;
|
49 | }
|
50 |
|
51 | return report({
|
52 | message: messages.expected(propertyName, atRuleName),
|
53 | node: atRule,
|
54 | result,
|
55 | ruleName,
|
56 | });
|
57 | });
|
58 | });
|
59 | };
|
60 | }
|
61 |
|
62 | rule.ruleName = ruleName;
|
63 | rule.messages = messages;
|
64 |
|
65 | module.exports = rule;
|