3 const blockString = require("../../utils/blockString");
4 const hasBlock = require("../../utils/hasBlock");
5 const hasEmptyBlock = require("../../utils/hasEmptyBlock");
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-before";
13 const messages = ruleMessages(ruleName, {
14 expectedBefore: () => 'Expected single space before "}"',
15 rejectedBefore: () => 'Unexpected whitespace before "}"',
16 expectedBeforeSingleLine: () =>
17 'Expected single space before "}" of a single-line block',
18 rejectedBeforeSingleLine: () =>
19 'Unexpected whitespace before "}" of a single-line block',
20 expectedBeforeMultiLine: () =>
21 'Expected single space before "}" of a multi-line block',
22 rejectedBeforeMultiLine: () =>
23 'Unexpected whitespace before "}" of a multi-line block'
26 const rule = function(expectation) {
27 const checker = whitespaceChecker("space", expectation, messages);
29 return (root, result) => {
30 const validOptions = validateOptions(result, ruleName, {
45 // Check both kinds of statement: rules and at-rules
46 root.walkRules(check);
47 root.walkAtRules(check);
49 function check(statement) {
50 // Return early if blockless or has empty block
51 if (!hasBlock(statement) || hasEmptyBlock(statement)) {
55 const source = blockString(statement);
56 const statementString = statement.toString();
58 let index = statementString.length - 2;
59 if (statementString[index - 1] === "\r") {
65 index: source.length - 1,
80 rule.ruleName = ruleName;
81 rule.messages = messages;
82 module.exports = rule;