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");
12 const ruleName = "block-opening-brace-space-after";
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'
27 const rule = function(expectation) {
28 const checker = whitespaceChecker("space", expectation, messages);
29 return (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 // Return early if blockless or has an empty block
51 if (!hasBlock(statement) || hasEmptyBlock(statement)) {
56 source: blockString(statement),
63 beforeBlockString(statement, { noRawBefore: true }).length + 1,
73 rule.ruleName = ruleName;
74 rule.messages = messages;
75 module.exports = rule;