Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions src/rules/selector-newline.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,30 @@ CSSLint.addRule({
init: function(parser, reporter) {
var rule = this;

parser.addListener("startrule", function(event) {
var i, len, selector, p, pLen, part, previousLine, currentLine,
function startRule(event) {
var i, len, selector, p, n, pLen, part, part2, type, currentLine, nextLine,
selectors = event.selectors;

for (i = 0, len = selectors.length; i < len; i++) {
selector = selectors[i];
for (p = 0, pLen = selector.parts.length; p < pLen; p++) {
part = selector.parts[p];
currentLine = part.line;
if (currentLine === previousLine) {
reporter.report("newline character found in selector (forgot a comma?)", currentLine, selectors[i].parts[0].col, rule);
for (n = p + 1; n < pLen; n++) {
part = selector.parts[p];
part2 = selector.parts[n];
type = part.type;
currentLine = part.line;
nextLine = part2.line;

if (type === "descendant" && nextLine > currentLine) {
reporter.report("newline character found in selector (forgot a comma?)", currentLine, selectors[i].parts[0].col, rule);
}
}
previousLine = currentLine;
}

}
});
}

parser.addListener("startrule", startRule);

}
});
3 changes: 3 additions & 0 deletions tests/rules/selector-newline.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
},
"a newline between selectors should not result in a warning": function () {
expectPass(".foo,\n.bar{}");
},
"'+' or '>' should not result in a warning": function () {
expectPass(".foo > .bar,\n.foo + .bar,\n.foo >\n.bar{}");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The third example here should fail due to the linebreak after the >

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No it shouldn't. Check out the branch locally to review and test...

}
}));

Expand Down