3 const isStandardSyntaxRule = require("../../utils/isStandardSyntaxRule");
4 const isStandardSyntaxSelector = require("../../utils/isStandardSyntaxSelector");
5 const parseSelector = require("../../utils/parseSelector");
6 const report = require("../../utils/report");
7 const ruleMessages = require("../../utils/ruleMessages");
8 const validateOptions = require("../../utils/validateOptions");
10 const ruleName = "selector-attribute-quotes";
12 const messages = ruleMessages(ruleName, {
13 expected: value => `Expected quotes around "${value}"`,
14 rejected: value => `Unexpected quotes around "${value}"`
17 const rule = function(expectation) {
18 return (root, result) => {
19 const validOptions = validateOptions(result, ruleName, {
21 possible: ["always", "never"]
27 root.walkRules(rule => {
28 if (!isStandardSyntaxRule(rule)) {
31 if (!isStandardSyntaxSelector(rule.selector)) {
35 rule.selector.indexOf("[") === -1 ||
36 rule.selector.indexOf("=") === -1
40 parseSelector(rule.selector, result, rule, selectorTree => {
41 selectorTree.walkAttributes(attributeNode => {
42 if (!attributeNode.operator) {
46 const attributeSelectorString = attributeNode.toString();
48 if (!attributeNode.quoted && expectation === "always") {
50 messages.expected(attributeNode.raws.unquoted),
51 attributeNode.sourceIndex +
52 attributeSelectorString.indexOf(attributeNode.value)
56 if (attributeNode.quoted && expectation === "never") {
58 messages.rejected(attributeNode.raws.unquoted),
59 attributeNode.sourceIndex +
60 attributeSelectorString.indexOf(attributeNode.value)
66 function complain(message, index) {
79 rule.ruleName = ruleName;
80 rule.messages = messages;
81 module.exports = rule;