stylelint
Version:
A mighty, modern CSS linter.
87 lines (67 loc) • 2.52 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.messages = exports.ruleName = undefined;
var _utils = require("../../utils");
var _lodash = require("lodash");
var _lodash2 = _interopRequireDefault(_lodash);
var _validateObjectWithStringArrayProps = require("../../utils/validateObjectWithStringArrayProps");
var _validateObjectWithStringArrayProps2 = _interopRequireDefault(_validateObjectWithStringArrayProps);
var _postcssValueParser = require("postcss-value-parser");
var _postcssValueParser2 = _interopRequireDefault(_postcssValueParser);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var ruleName = exports.ruleName = "unit-blacklist";
var messages = exports.messages = (0, _utils.ruleMessages)(ruleName, {
rejected: function rejected(unit) {
return "Unexpected unit \"" + unit + "\"";
}
});
function rule(blacklistInput, options) {
var blacklist = [].concat(blacklistInput);
return function (root, result) {
var validOptions = (0, _utils.validateOptions)(result, ruleName, {
actual: blacklist,
possible: [_lodash2.default.isString]
}, {
optional: true,
actual: options,
possible: {
ignoreProperties: _validateObjectWithStringArrayProps2.default
}
});
if (!validOptions) {
return;
}
function check(node, value, getIndex) {
(0, _postcssValueParser2.default)(value).walk(function (valueNode) {
// Ignore wrong units within `url` function
if (valueNode.type === "function" && valueNode.value.toLowerCase() === "url") {
return false;
}
var unit = (0, _utils.getUnitFromValueNode)(valueNode);
if (!unit || unit && blacklist.indexOf(unit.toLowerCase()) === -1) {
return;
}
if (options && (0, _utils.optionsMatches)(options.ignoreProperties, unit.toLowerCase(), node.prop)) {
return;
}
(0, _utils.report)({
index: getIndex(node) + valueNode.sourceIndex,
message: messages.rejected(unit),
node: node,
result: result,
ruleName: ruleName
});
});
}
root.walkAtRules(/^media$/i, function (atRule) {
return check(atRule, atRule.params, _utils.atRuleParamIndex);
});
root.walkDecls(function (decl) {
return check(decl, decl.value, _utils.declarationValueIndex);
});
};
}
rule.primaryOptionArray = true;
exports.default = rule;