.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / stylelint / lib / rules / block-closing-brace-space-after / index.js
1 "use strict";
2
3 const blockString = require("../../utils/blockString");
4 const hasBlock = require("../../utils/hasBlock");
5 const rawNodeString = require("../../utils/rawNodeString");
6 const report = require("../../utils/report");
7 const ruleMessages = require("../../utils/ruleMessages");
8 const validateOptions = require("../../utils/validateOptions");
9 const whitespaceChecker = require("../../utils/whitespaceChecker");
10
11 const ruleName = "block-closing-brace-space-after";
12
13 const messages = ruleMessages(ruleName, {
14   expectedAfter: () => 'Expected single space after "}"',
15   rejectedAfter: () => 'Unexpected whitespace after "}"',
16   expectedAfterSingleLine: () =>
17     'Expected single space after "}" of a single-line block',
18   rejectedAfterSingleLine: () =>
19     'Unexpected whitespace after "}" of a single-line block',
20   expectedAfterMultiLine: () =>
21     'Expected single space after "}" of a multi-line block',
22   rejectedAfterMultiLine: () =>
23     'Unexpected whitespace after "}" of a multi-line block'
24 });
25
26 const rule = function(expectation) {
27   const checker = whitespaceChecker("space", expectation, messages);
28
29   return function(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       const nextNode = statement.next();
51       if (!nextNode) {
52         return;
53       }
54       if (!hasBlock(statement)) {
55         return;
56       }
57
58       let reportIndex = statement.toString().length;
59       let source = rawNodeString(nextNode);
60
61       // Skip a semicolon at the beginning, if any
62       if (source && source[0] === ";") {
63         source = source.slice(1);
64         reportIndex++;
65       }
66
67       checker.after({
68         source,
69         index: -1,
70         lineCheckStr: blockString(statement),
71         err: msg => {
72           report({
73             message: msg,
74             node: statement,
75             index: reportIndex,
76             result,
77             ruleName
78           });
79         }
80       });
81     }
82   };
83 };
84
85 rule.ruleName = ruleName;
86 rule.messages = messages;
87 module.exports = rule;