stylelint
Version:
Modern CSS linter
90 lines (75 loc) • 2.47 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.messages = exports.ruleName = undefined;
exports.default = function (actual) {
return function (root, result) {
var validOptions = (0, _utils.validateOptions)(result, ruleName, { actual: actual });
if (!validOptions) {
return;
}
root.walkDecls(function (decl, index) {
var prop = decl.prop;
var value = decl.value;
var unprefixedProp = _postcss.vendor.unprefixed(prop);
var unprefixedValue = _postcss.vendor.unprefixed(value);
ignored.forEach(function (ignore) {
var matchProperty = (0, _utils.matchesStringOrRegExp)(unprefixedProp, ignore.property);
var matchValue = (0, _utils.matchesStringOrRegExp)(unprefixedValue, ignore.value);
if (!matchProperty || !matchValue) {
return;
}
var ignoredProperties = ignore.ignoredProperties;
decl.parent.nodes.forEach(function (node, nodeIndex) {
if (ignoredProperties.indexOf(node.prop) === -1 || index === nodeIndex) {
return;
}
(0, _utils.report)({
message: messages.rejected(node.prop, decl.toString()),
node: node,
result: result,
ruleName: ruleName
});
});
});
});
};
};
var _postcss = require("postcss");
var _utils = require("../../utils");
var ruleName = exports.ruleName = "declaration-block-no-ignored-properties";
var messages = exports.messages = (0, _utils.ruleMessages)(ruleName, {
rejected: function rejected(ignored, cause) {
return "Unexpected property \"" + ignored + "\" that is ignored because of \"" + cause + "\"";
}
});
var ignored = [{
property: "display",
value: "inline",
ignoredProperties: ["width", "height", "margin", "margin-top", "margin-bottom", "float"]
}, {
property: "display",
value: "inline-block",
ignoredProperties: ["float"]
}, {
property: "display",
value: "block",
ignoredProperties: ["vertical-align"]
}, {
property: "display",
value: "/^table-.*$/",
ignoredProperties: ["margin", "margin-top", "margin-right", "margin-bottom", "margin-left", "float"]
}, {
property: "position",
value: "static",
ignoredProperties: ["top", "right", "bottom", "left"]
}, {
property: "position",
value: "absolute",
ignoredProperties: ["float"]
}, {
property: "position",
value: "fixed",
ignoredProperties: ["float"]
}];