UNPKG

stylelint

Version:
68 lines (57 loc) 2.01 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.messages = exports.ruleName = undefined; exports.default = function (expectation) { return function (root, result) { var validOptions = (0, _utils.validateOptions)(result, ruleName, { actual: expectation, possible: ["always", "never"] }); if (!validOptions) { return; } root.walkRules(function (rule) { if (!(0, _utils.isStandardSyntaxRule)(rule)) { return; } if (rule.selector.indexOf("[") === -1 || rule.selector.indexOf("=") === -1) { return; } (0, _utils.parseSelector)(rule.selector, result, rule, function (selectorTree) { selectorTree.walkAttributes(function (attributeNode) { if (!attributeNode.operator) { return; } var attributeSelectorString = attributeNode.toString(); if (!attributeNode.quoted && expectation === "always") { complain(messages.expected(attributeNode.raws.unquoted), attributeNode.sourceIndex + attributeSelectorString.indexOf(attributeNode.value)); } if (attributeNode.quoted && expectation === "never") { complain(messages.rejected(attributeNode.raws.unquoted), attributeNode.sourceIndex + attributeSelectorString.indexOf(attributeNode.value)); } }); }); function complain(message, index) { (0, _utils.report)({ message: message, index: index, result: result, ruleName: ruleName, node: rule }); } }); }; }; var _utils = require("../../utils"); var ruleName = exports.ruleName = "selector-attribute-quotes"; var messages = exports.messages = (0, _utils.ruleMessages)(ruleName, { expected: function expected(value) { return "Expected quotes around \"" + value + "\""; }, rejected: function rejected(value) { return "Unexpected quotes around \"" + value + "\""; } });