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");
11 const ruleName = "block-closing-brace-space-after";
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'
26 const rule = function(expectation) {
27 const checker = whitespaceChecker("space", expectation, messages);
29 return function(root, result) {
30 const validOptions = validateOptions(result, ruleName, {
45 // Check both kinds of statements: rules and at-rules
46 root.walkRules(check);
47 root.walkAtRules(check);
49 function check(statement) {
50 const nextNode = statement.next();
54 if (!hasBlock(statement)) {
58 let reportIndex = statement.toString().length;
59 let source = rawNodeString(nextNode);
61 // Skip a semicolon at the beginning, if any
62 if (source && source[0] === ";") {
63 source = source.slice(1);
70 lineCheckStr: blockString(statement),
85 rule.ruleName = ruleName;
86 rule.messages = messages;
87 module.exports = rule;