.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / stylelint / lib / rules / media-feature-range-operator-space-before / index.js
1 "use strict";
2
3 const atRuleParamIndex = require("../../utils/atRuleParamIndex");
4 const findMediaOperator = require("../findMediaOperator");
5 const report = require("../../utils/report");
6 const ruleMessages = require("../../utils/ruleMessages");
7 const validateOptions = require("../../utils/validateOptions");
8 const whitespaceChecker = require("../../utils/whitespaceChecker");
9
10 const ruleName = "media-feature-range-operator-space-before";
11
12 const messages = ruleMessages(ruleName, {
13   expectedBefore: () => "Expected single space before range operator",
14   rejectedBefore: () => "Unexpected whitespace before range operator"
15 });
16
17 const rule = function(expectation) {
18   const checker = whitespaceChecker("space", expectation, messages);
19   return (root, result) => {
20     const validOptions = validateOptions(result, ruleName, {
21       actual: expectation,
22       possible: ["always", "never"]
23     });
24     if (!validOptions) {
25       return;
26     }
27
28     root.walkAtRules(/^media$/i, atRule => {
29       findMediaOperator(atRule, checkBeforeOperator);
30     });
31
32     function checkBeforeOperator(match, params, node) {
33       // The extra `+ 1` is because the match itself contains
34       // the character before the operator
35       checker.before({
36         source: params,
37         index: match.index + 1,
38         err: m => {
39           report({
40             message: m,
41             node,
42             index: match.index + atRuleParamIndex(node),
43             result,
44             ruleName
45           });
46         }
47       });
48     }
49   };
50 };
51
52 rule.ruleName = ruleName;
53 rule.messages = messages;
54 module.exports = rule;