3 const isStandardSyntaxRule = require("../../utils/isStandardSyntaxRule");
4 const report = require("../../utils/report");
5 const ruleMessages = require("../../utils/ruleMessages");
6 const styleSearch = require("style-search");
7 const validateOptions = require("../../utils/validateOptions");
8 const whitespaceChecker = require("../../utils/whitespaceChecker");
10 const ruleName = "selector-list-comma-newline-after";
12 const messages = ruleMessages(ruleName, {
13 expectedAfter: () => 'Expected newline after ","',
14 expectedAfterMultiLine: () =>
15 'Expected newline after "," in a multi-line list',
16 rejectedAfterMultiLine: () =>
17 'Unexpected whitespace after "," in a multi-line list'
20 const rule = function(expectation) {
21 const checker = whitespaceChecker("newline", expectation, messages);
22 return (root, result) => {
23 const validOptions = validateOptions(result, ruleName, {
25 possible: ["always", "always-multi-line", "never-multi-line"]
31 root.walkRules(rule => {
32 if (!isStandardSyntaxRule(rule)) {
35 // Get raw selector so we can allow end-of-line comments, e.g.
38 const selector = rule.raws.selector
39 ? rule.raws.selector.raw
45 functionArguments: "skip"
48 const nextChars = selector.substr(
50 selector.length - match.endIndex
53 // If there's a // comment, that means there has to be a newline
54 // ending the comment so we're fine
55 if (nextChars.match(/^\s+\/\//)) {
59 // If there are spaces and then a comment begins, look for the newline
60 const indextoCheckAfter = nextChars.match(/^\s+\/\*/)
61 ? selector.indexOf("*/", match.endIndex) + 1
63 checker.afterOneOnly({
65 index: indextoCheckAfter,
70 index: match.startIndex,
81 rule.ruleName = ruleName;
82 rule.messages = messages;
83 module.exports = rule;