UNPKG

stylelint

Version:
86 lines (67 loc) 2.42 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.messages = exports.ruleName = undefined; exports.default = function (actual, options) { return function (root, result) { var validOptions = (0, _utils.validateOptions)(result, ruleName, { actual: actual }, { actual: options, possible: { ignoreShorthands: [_lodash.isString] }, optional: true }); if (!validOptions) { return; } var longhandProperties = (0, _lodash.transform)(_shorthandData2.default, function (result, values, key) { if ((0, _utils.optionsMatches)(options, "ignoreShorthands", key)) { return; } values.forEach(function (value) { (result[value] || (result[value] = [])).push(key); }); }); root.walkRules(check); root.walkAtRules(check); function check(statement) { var longhandDeclarations = {}; // Shallow iteration so nesting doesn't produce // false positives statement.each(function (node) { if (node.type !== "decl") { return; } var prop = node.prop.toLowerCase(); var shorthandProperties = longhandProperties[prop]; if (!shorthandProperties) { return; } shorthandProperties.forEach(function (shorthandProperty) { (longhandDeclarations[shorthandProperty] || (longhandDeclarations[shorthandProperty] = [])).push(prop); if (!(0, _lodash.isEqual)(_shorthandData2.default[shorthandProperty].sort(), longhandDeclarations[shorthandProperty].sort())) { return; } (0, _utils.report)({ ruleName: ruleName, result: result, node: node, message: messages.expected(shorthandProperty) }); }); }); } }; }; var _lodash = require("lodash"); var _utils = require("../../utils"); var _shorthandData = require("../../reference/shorthandData"); var _shorthandData2 = _interopRequireDefault(_shorthandData); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var ruleName = exports.ruleName = "declaration-block-no-redundant-longhand-properties"; var messages = exports.messages = (0, _utils.ruleMessages)(ruleName, { expected: function expected(props) { return "Expected shorthand property \"" + props + "\""; } });