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");
9 const ruleName = "declaration-block-no-shorthand-property-overrides";
11 const messages = ruleMessages(ruleName, {
12 rejected: (shorthand, original) =>
13 `Unexpected shorthand "${shorthand}" after "${original}"`
16 const rule = function(actual) {
17 return (root, result) => {
18 const validOptions = validateOptions(result, ruleName, { actual });
23 root.walkRules(check);
24 root.walkAtRules(check);
26 function check(statement) {
27 const declarations = {};
28 // Shallow iteration so nesting doesn't produce
30 statement.each(node => {
31 if (node.type !== "decl") {
35 const prop = node.prop;
36 const unprefixedProp = postcss.vendor.unprefixed(prop);
37 const prefix = postcss.vendor.prefix(prop).toLowerCase();
39 const overrideables = shorthandData[unprefixedProp.toLowerCase()];
41 declarations[prop.toLowerCase()] = prop;
44 overrideables.forEach(longhandProp => {
45 if (!declarations.hasOwnProperty(prefix + longhandProp)) {
52 message: messages.rejected(
54 declarations[prefix + longhandProp]
63 rule.ruleName = ruleName;
64 rule.messages = messages;
65 module.exports = rule;