3 const declarationValueIndex = require("../../utils/declarationValueIndex");
4 const isStandardSyntaxDeclaration = require("../../utils/isStandardSyntaxDeclaration");
5 const report = require("../../utils/report");
6 const ruleMessages = require("../../utils/ruleMessages");
7 const validateOptions = require("../../utils/validateOptions");
8 const whitespaceChecker = require("../../utils/whitespaceChecker");
10 const ruleName = "declaration-colon-newline-after";
12 const messages = ruleMessages(ruleName, {
13 expectedAfter: () => 'Expected newline after ":"',
14 expectedAfterMultiLine: () =>
15 'Expected newline after ":" with a multi-line declaration'
18 const rule = function(expectation) {
19 const checker = whitespaceChecker("newline", expectation, messages);
20 return (root, result) => {
21 const validOptions = validateOptions(result, ruleName, {
23 possible: ["always", "always-multi-line"]
29 root.walkDecls(decl => {
30 if (!isStandardSyntaxDeclaration(decl)) {
34 // Get the raw prop, and only the prop
35 const endOfPropIndex =
36 declarationValueIndex(decl) + (decl.raws.between || "").length - 1;
38 // The extra characters tacked onto the end ensure that there is a character to check
39 // after the colon. Otherwise, with `background:pink` the character after the
40 const propPlusColon = decl.toString().slice(0, endOfPropIndex) + "xxx";
42 for (let i = 0, l = propPlusColon.length; i < l; i++) {
43 if (propPlusColon[i] !== ":") {
47 propPlusColon.substr(propPlusColon[i], 3) === "/*"
48 ? propPlusColon.indexOf("*/", i) + 1
51 checker.afterOneOnly({
52 source: propPlusColon,
54 lineCheckStr: decl.value,
70 rule.ruleName = ruleName;
71 rule.messages = messages;
72 module.exports = rule;