.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / stylelint / lib / rules / block-opening-brace-space-after / index.js
1 "use strict";
2
3 const beforeBlockString = require("../../utils/beforeBlockString");
4 const blockString = require("../../utils/blockString");
5 const hasBlock = require("../../utils/hasBlock");
6 const hasEmptyBlock = require("../../utils/hasEmptyBlock");
7 const report = require("../../utils/report");
8 const ruleMessages = require("../../utils/ruleMessages");
9 const validateOptions = require("../../utils/validateOptions");
10 const whitespaceChecker = require("../../utils/whitespaceChecker");
11
12 const ruleName = "block-opening-brace-space-after";
13
14 const messages = ruleMessages(ruleName, {
15   expectedAfter: () => 'Expected single space after "{"',
16   rejectedAfter: () => 'Unexpected whitespace after "{"',
17   expectedAfterSingleLine: () =>
18     'Expected single space after "{" of a single-line block',
19   rejectedAfterSingleLine: () =>
20     'Unexpected whitespace after "{" of a single-line block',
21   expectedAfterMultiLine: () =>
22     'Expected single space after "{" of a multi-line block',
23   rejectedAfterMultiLine: () =>
24     'Unexpected whitespace after "{" of a multi-line block'
25 });
26
27 const rule = function(expectation) {
28   const checker = whitespaceChecker("space", expectation, messages);
29   return (root, result) => {
30     const validOptions = validateOptions(result, ruleName, {
31       actual: expectation,
32       possible: [
33         "always",
34         "never",
35         "always-single-line",
36         "never-single-line",
37         "always-multi-line",
38         "never-multi-line"
39       ]
40     });
41     if (!validOptions) {
42       return;
43     }
44
45     // Check both kinds of statements: rules and at-rules
46     root.walkRules(check);
47     root.walkAtRules(check);
48
49     function check(statement) {
50       // Return early if blockless or has an empty block
51       if (!hasBlock(statement) || hasEmptyBlock(statement)) {
52         return;
53       }
54
55       checker.after({
56         source: blockString(statement),
57         index: 0,
58         err: m => {
59           report({
60             message: m,
61             node: statement,
62             index:
63               beforeBlockString(statement, { noRawBefore: true }).length + 1,
64             result,
65             ruleName
66           });
67         }
68       });
69     }
70   };
71 };
72
73 rule.ruleName = ruleName;
74 rule.messages = messages;
75 module.exports = rule;