.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / stylelint / lib / rules / declaration-block-no-shorthand-property-overrides / index.js
1 "use strict";
2
3 const postcss = require("postcss");
4 const report = require("../../utils/report");
5 const ruleMessages = require("../../utils/ruleMessages");
6 const shorthandData = require("../../reference/shorthandData");
7 const validateOptions = require("../../utils/validateOptions");
8
9 const ruleName = "declaration-block-no-shorthand-property-overrides";
10
11 const messages = ruleMessages(ruleName, {
12   rejected: (shorthand, original) =>
13     `Unexpected shorthand "${shorthand}" after "${original}"`
14 });
15
16 const rule = function(actual) {
17   return (root, result) => {
18     const validOptions = validateOptions(result, ruleName, { actual });
19     if (!validOptions) {
20       return;
21     }
22
23     root.walkRules(check);
24     root.walkAtRules(check);
25
26     function check(statement) {
27       const declarations = {};
28       // Shallow iteration so nesting doesn't produce
29       // false positives
30       statement.each(node => {
31         if (node.type !== "decl") {
32           return;
33         }
34
35         const prop = node.prop;
36         const unprefixedProp = postcss.vendor.unprefixed(prop);
37         const prefix = postcss.vendor.prefix(prop).toLowerCase();
38
39         const overrideables = shorthandData[unprefixedProp.toLowerCase()];
40         if (!overrideables) {
41           declarations[prop.toLowerCase()] = prop;
42           return;
43         }
44         overrideables.forEach(longhandProp => {
45           if (!declarations.hasOwnProperty(prefix + longhandProp)) {
46             return;
47           }
48           report({
49             ruleName,
50             result,
51             node,
52             message: messages.rejected(
53               prop,
54               declarations[prefix + longhandProp]
55             )
56           });
57         });
58       });
59     }
60   };
61 };
62
63 rule.ruleName = ruleName;
64 rule.messages = messages;
65 module.exports = rule;