.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / stylelint / lib / rules / media-feature-parentheses-space-inside / index.js
1 "use strict";
2
3 const _ = require("lodash");
4 const atRuleParamIndex = require("../../utils/atRuleParamIndex");
5 const report = require("../../utils/report");
6 const ruleMessages = require("../../utils/ruleMessages");
7 const styleSearch = require("style-search");
8 const validateOptions = require("../../utils/validateOptions");
9
10 const ruleName = "media-feature-parentheses-space-inside";
11
12 const messages = ruleMessages(ruleName, {
13   expectedOpening: 'Expected single space after "("',
14   rejectedOpening: 'Unexpected whitespace after "("',
15   expectedClosing: 'Expected single space before ")"',
16   rejectedClosing: 'Unexpected whitespace before ")"'
17 });
18
19 const rule = function(expectation) {
20   return (root, result) => {
21     const validOptions = validateOptions(result, ruleName, {
22       actual: expectation,
23       possible: ["always", "never"]
24     });
25     if (!validOptions) {
26       return;
27     }
28
29     root.walkAtRules(/^media$/i, atRule => {
30       // If there are comments in the params, the complete string
31       // will be at atRule.raws.params.raw
32       const params = _.get(atRule, "raws.params.raw", atRule.params);
33       const indexBoost = atRuleParamIndex(atRule);
34
35       styleSearch({ source: params, target: "(" }, match => {
36         const nextCharIsSpace = params[match.startIndex + 1] === " ";
37         if (nextCharIsSpace && expectation === "never") {
38           report({
39             message: messages.rejectedOpening,
40             node: atRule,
41             index: match.startIndex + 1 + indexBoost,
42             result,
43             ruleName
44           });
45         }
46         if (!nextCharIsSpace && expectation === "always") {
47           report({
48             message: messages.expectedOpening,
49             node: atRule,
50             index: match.startIndex + 1 + indexBoost,
51             result,
52             ruleName
53           });
54         }
55       });
56
57       styleSearch({ source: params, target: ")" }, match => {
58         const prevCharIsSpace = params[match.startIndex - 1] === " ";
59         if (prevCharIsSpace && expectation === "never") {
60           report({
61             message: messages.rejectedClosing,
62             node: atRule,
63             index: match.startIndex - 1 + indexBoost,
64             result,
65             ruleName
66           });
67         }
68         if (!prevCharIsSpace && expectation === "always") {
69           report({
70             message: messages.expectedClosing,
71             node: atRule,
72             index: match.startIndex - 1 + indexBoost,
73             result,
74             ruleName
75           });
76         }
77       });
78     });
79   };
80 };
81
82 rule.ruleName = ruleName;
83 rule.messages = messages;
84 module.exports = rule;