stylelint
Version:
A mighty, modern CSS linter.
101 lines (87 loc) • 3.06 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.messages = exports.ruleName = undefined;
exports.default = function (expectation, options) {
var checker = (0, _utils.whitespaceChecker)("newline", expectation, messages);
return function (root, result) {
var validOptions = (0, _utils.validateOptions)(result, ruleName, {
actual: expectation,
possible: ["always", "always-single-line", "never-single-line", "always-multi-line", "never-multi-line"]
}, {
actual: options,
possible: {
ignoreAtRules: [_lodash.isString]
},
optional: true
});
if (!validOptions) {
return;
}
// Check both kinds of statements: rules and at-rules
root.walkRules(check);
root.walkAtRules(check);
function check(statement) {
if (!(0, _utils.hasBlock)(statement)) {
return;
}
if ((0, _utils.optionsMatches)(options, "ignoreAtRules", statement.name)) {
return;
}
var nextNode = statement.next();
if (!nextNode) {
return;
}
// Allow an end-of-line comment x spaces after the brace
var nextNodeIsSingleLineComment = nextNode.type === "comment" && !/[^ ]/.test(nextNode.raw("before")) && nextNode.toString().indexOf("\n") === -1;
var nodeToCheck = nextNodeIsSingleLineComment ? nextNode.next() : nextNode;
if (!nodeToCheck) {
return;
}
var reportIndex = statement.toString().length;
var source = (0, _utils.rawNodeString)(nodeToCheck);
// Skip a semicolon at the beginning, if any
if (source && source[0] === ";") {
source = source.slice(1);
reportIndex++;
}
// Only check one after, because there might be other
// spaces handled by the indentation rule
checker.afterOneOnly({
source: source,
index: -1,
lineCheckStr: (0, _utils.blockString)(statement),
err: function err(msg) {
(0, _utils.report)({
message: msg,
node: statement,
index: reportIndex,
result: result,
ruleName: ruleName
});
}
});
}
};
};
var _utils = require("../../utils");
var _lodash = require("lodash");
var ruleName = exports.ruleName = "block-closing-brace-newline-after";
var messages = exports.messages = (0, _utils.ruleMessages)(ruleName, {
expectedAfter: function expectedAfter() {
return "Expected newline after \"}\"";
},
expectedAfterSingleLine: function expectedAfterSingleLine() {
return "Expected newline after \"}\" of a single-line block";
},
rejectedAfterSingleLine: function rejectedAfterSingleLine() {
return "Unexpected whitespace after \"}\" of a single-line block";
},
expectedAfterMultiLine: function expectedAfterMultiLine() {
return "Expected newline after \"}\" of a multi-line block";
},
rejectedAfterMultiLine: function rejectedAfterMultiLine() {
return "Unexpected whitespace after \"}\" of a multi-line block";
}
});