Skip to content

Commit 9a9afa9

Browse files
authored
Merge pull request CSSLint#698 from CSSLint/ignore_now_ignores_rollup
Rollups now support ignore. Fixes CSSLint#685
2 parents 6b1d395 + 115762a commit 9a9afa9

File tree

12 files changed

+67
-18
lines changed

12 files changed

+67
-18
lines changed

src/core/Reporter.js

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @param {Object} ruleset The set of rules to work with, including if
88
* they are errors or warnings.
99
* @param {Object} explicitly allowed lines
10-
* @param {[][]} ingore list of line ranges to be ignored
10+
* @param {[][]} ignore list of line ranges to be ignored
1111
*/
1212
function Reporter(lines, ruleset, allow, ignore) {
1313
"use strict";
@@ -118,13 +118,7 @@ Reporter.prototype = {
118118
return;
119119
}
120120

121-
var ignore = false;
122-
CSSLint.Util.forEach(this.ignore, function (range) {
123-
if (range[0] <= line && line <= range[1]) {
124-
ignore = true;
125-
}
126-
});
127-
if (ignore) {
121+
if (this.isIgnored(line)) {
128122
return;
129123
}
130124

@@ -199,6 +193,23 @@ Reporter.prototype = {
199193
stat: function(name, value) {
200194
"use strict";
201195
this.stats[name] = value;
196+
},
197+
198+
/**
199+
* Helper function to check if a line is ignored
200+
* @param {int} line Line to check for ignore-status
201+
* @method isIgnored
202+
* @return {Boolean} True if the line is ignored, else false
203+
*/
204+
isIgnored: function(line) {
205+
"use strict";
206+
var ignore = false;
207+
CSSLint.Util.forEach(this.ignore, function (range) {
208+
if (range[0] <= line && line <= range[1]) {
209+
ignore = true;
210+
}
211+
});
212+
return ignore;
202213
}
203214
};
204215

src/rules/empty-rules.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ CSSLint.addRule({
2727

2828
parser.addListener("endrule", function(event) {
2929
var selectors = event.selectors;
30+
3031
if (count === 0) {
3132
reporter.report("Rule is empty.", selectors[0].line, selectors[0].col, rule);
3233
}

src/rules/floats.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@ CSSLint.addRule({
2020

2121
// count how many times "float" is used
2222
parser.addListener("property", function(event) {
23-
if (event.property.text.toLowerCase() === "float" &&
24-
event.value.text.toLowerCase() !== "none") {
25-
count++;
23+
if (!reporter.isIgnored(event.property.line)) {
24+
if (event.property.text.toLowerCase() === "float" &&
25+
event.value.text.toLowerCase() !== "none") {
26+
count++;
27+
}
2628
}
2729
});
2830

src/rules/font-faces.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ CSSLint.addRule({
1818
count = 0;
1919

2020

21-
parser.addListener("startfontface", function() {
22-
count++;
21+
parser.addListener("startfontface", function(event) {
22+
if (!reporter.isIgnored(event.line)) {
23+
count++;
24+
}
2325
});
2426

2527
parser.addListener("endstylesheet", function() {

src/rules/font-sizes.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ CSSLint.addRule({
1919

2020
// check for use of "font-size"
2121
parser.addListener("property", function(event) {
22-
if (event.property.toString() === "font-size") {
23-
count++;
22+
if (!reporter.isIgnored(event.property.line)) {
23+
if (event.property.toString() === "font-size") {
24+
count++;
25+
}
2426
}
2527
});
2628

src/rules/important.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ CSSLint.addRule({
2121

2222
// warn that important is used and increment the declaration counter
2323
parser.addListener("property", function(event) {
24-
if (event.important === true) {
25-
count++;
26-
reporter.report("Use of !important", event.line, event.col, rule);
24+
if (!reporter.isIgnored(event.line)) {
25+
if (event.important === true) {
26+
count++;
27+
reporter.report("Use of !important", event.line, event.col, rule);
28+
}
2729
}
2830
});
2931

src/rules/unique-headings.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ CSSLint.addRule({
3636
selector = selectors[i];
3737
part = selector.parts[selector.parts.length-1];
3838

39+
if (reporter.isIgnored(part.line)) {
40+
continue;
41+
}
42+
3943
if (part.elementName && /(h[1-6])/i.test(part.elementName.toString())) {
4044

4145
for (j=0; j < part.modifiers.length; j++) {

tests/rules/floats.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@
2828
"float: none should not count and therefore should not result in a warning": function() {
2929
var result = CSSLint.verify(".foo { float: none; } .foo { float: left; } .foo { float: left; } .foo { float: left; } .foo { float: left; } .foo { float: left; } .foo { float: left; } .foo { float: left; } .foo { float: left; } .foo { float: left; }", { "floats": 1 });
3030
Assert.areEqual(0, result.messages.length);
31+
},
32+
33+
"Ignore should remove rollup warning message for floats": function() {
34+
var report = CSSLint.verify("/* csslint ignore:start */\n.test1 {float:left}\n.test2 {float:left}\n.test3 {float:left}\n.test4 {float:left}\n.test5 {float:left}\n.test6 {float:left}\n.test7 {float:left}\n.test8 {float:left}\n.test9 {float:left}\n.test10 {float:left}\n.test11 {float:left}\n/* csslint ignore:end */h2 {color: #fff}\n");
35+
Assert.areEqual(0, report.messages.length);
3136
}
3237
}));
3338

tests/rules/font-faces.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121
Assert.areEqual(1, result.messages.length);
2222
Assert.areEqual("warning", result.messages[0].type);
2323
Assert.areEqual("Too many @font-face declarations (6).", result.messages[0].message);
24+
},
25+
26+
"Ignore should remove rollup warning message for font-face": function() {
27+
var report = CSSLint.verify("/* csslint ignore:start */\n@font-face{} @font-face{} @font-face{} @font-face{} @font-face{} @font-face{}\n/* csslint ignore:end */@font-face{}\n");
28+
Assert.areEqual(0, report.messages.length);
2429
}
2530
}));
2631

tests/rules/font-sizes.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@
2323
Assert.areEqual(1, result.messages.length);
2424
Assert.areEqual("warning", result.messages[0].type);
2525
Assert.areEqual("Too many font-size declarations (11), abstraction needed.", result.messages[0].message);
26+
},
27+
28+
"Ignore should remove rollup warning message for font-sizes": function() {
29+
var report = CSSLint.verify("/* csslint ignore:start */\n.test1 {font-size: 10px;}\n.test2 {font-size: 10px;}\n.test3 {font-size: 10px;}\n.test4 {font-size: 10px;}\n.test5 {font-size: 10px;}\n.test6 {font-size: 10px;}\n.test7 {font-size: 10px;}\n.test8 {font-size: 10px;}\n.test9 {font-size: 10px;}\n.test10 {font-size: 10px;}\n.test11 {font-size: 10px;}\n/* csslint ignore:end */h2 {color: #fff}\n");
30+
Assert.areEqual(0, report.messages.length);
2631
}
2732
}));
2833

tests/rules/important.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
Assert.areEqual(11, result.messages.length);
2020
Assert.areEqual("warning", result.messages[10].type);
2121
Assert.areEqual("Too many !important declarations (10), try to use less than 10 to avoid specificity issues.", result.messages[10].message);
22+
},
23+
24+
"Ignore should remove rollup warning message for important": function() {
25+
var report = CSSLint.verify("/* csslint ignore:start */\n.test1 {color:#fff !important;}\n.test2 {color:#fff !important;}\n.test3 {color:#fff !important;}\n.test4 {color:#fff !important;}\n.test5 {color:#fff !important;}\n.test6 {color:#fff !important;}\n.test7 {color:#fff !important;}\n.test8 {color:#fff !important;}\n.test9 {color:#fff !important;}\n.test10 {color:#fff !important;}\n.test11 {color:#fff !important;}\n/* csslint ignore:end */h2 {color: #fff}\n");
26+
Assert.areEqual(0, report.messages.length);
2227
}
2328

2429
}));

tests/rules/unique-headings.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@
3939
"Defining multiple rules that contain h1 should not result in a warning": function() {
4040
var result = CSSLint.verify("h2 a, h2 a:active, h2 a:hover, h2 a:visited, h2 a:link { color: red;}", { "unique-headings": 1 });
4141
Assert.areEqual(0, result.messages.length);
42+
},
43+
44+
"Ignore should remove rollup warning messages for unique headings": function() {
45+
var report = CSSLint.verify("/* csslint ignore:start */\nh1 {color: #f0f}\nh1 {color: #ff0}/* csslint ignore:end */h2 {color: #fff}\n");
46+
Assert.areEqual(0, report.messages.length);
4247
}
4348

4449
}));

0 commit comments

Comments
 (0)