Skip to content

Commit b06d61d

Browse files
committed
Whitespace cleanup.
[ci skip]
1 parent 77b08b1 commit b06d61d

10 files changed

+259
-44
lines changed

dist/csslint-node.js

+41-7
Original file line numberDiff line numberDiff line change
@@ -202,13 +202,30 @@ var CSSLint = (function() {
202202
var i = 0,
203203
reporter,
204204
lines,
205+
allow = {},
205206
report,
206207
parser = new parserlib.css.Parser({ starHack: true, ieFilters: true,
207208
underscoreHack: true, strict: false });
208209

209210
// normalize line endings
210211
lines = text.replace(/\n\r?/g, "$split$").split("$split$");
211212

213+
// find 'allow' comments
214+
CSSLint.Util.forEach(lines, function (line, lineno) {
215+
var allowLine = line && line.match(/\/\*[ \t]*csslint[ \t]+allow:[ \t]*([^\*]*)\*\//i),
216+
allowRules = allowLine && allowLine[1],
217+
allowRuleset = {};
218+
219+
if (allowRules) {
220+
allowRules.toLowerCase().split(",").forEach(function(allowRule){
221+
allowRuleset[allowRule.trim()] = true;
222+
});
223+
if (Object.keys(allowRuleset).length > 0) {
224+
allow[lineno + 1] = allowRuleset;
225+
}
226+
}
227+
});
228+
212229
if (!ruleset) {
213230
ruleset = this.getRuleset();
214231
}
@@ -219,7 +236,7 @@ var CSSLint = (function() {
219236
ruleset = applyEmbeddedRuleset(text, ruleset);
220237
}
221238

222-
reporter = new Reporter(lines, ruleset);
239+
reporter = new Reporter(lines, ruleset, allow);
223240

224241
ruleset.errors = 2; //always report parsing errors as errors
225242
for (i in ruleset) {
@@ -241,7 +258,8 @@ var CSSLint = (function() {
241258
report = {
242259
messages : reporter.messages,
243260
stats : reporter.stats,
244-
ruleset : reporter.ruleset
261+
ruleset : reporter.ruleset,
262+
allow : reporter.allow
245263
};
246264

247265
//sort by line numbers, rollups at the bottom
@@ -275,7 +293,7 @@ var CSSLint = (function() {
275293
* @param {Object} ruleset The set of rules to work with, including if
276294
* they are errors or warnings.
277295
*/
278-
function Reporter(lines, ruleset) {
296+
function Reporter(lines, ruleset, allow) {
279297
"use strict";
280298

281299
/**
@@ -307,6 +325,16 @@ function Reporter(lines, ruleset) {
307325
* @type Object
308326
*/
309327
this.ruleset = ruleset;
328+
329+
/**
330+
* Lines with specific rule messages to leave out of the report.
331+
* @property allow
332+
* @type Object
333+
*/
334+
this.allow = allow;
335+
if(!this.allow) {
336+
this.allow = {};
337+
}
310338
}
311339

312340
Reporter.prototype = {
@@ -358,6 +386,12 @@ Reporter.prototype = {
358386
*/
359387
report: function(message, line, col, rule) {
360388
"use strict";
389+
390+
// Check if rule violation should be allowed
391+
if (this.allow.hasOwnProperty(line) && this.allow[line].hasOwnProperty(rule.id)) {
392+
return;
393+
}
394+
361395
this.messages.push({
362396
type : this.ruleset[rule.id] === 2 ? "error" : "warning",
363397
line : line,
@@ -1526,19 +1560,19 @@ CSSLint.addRule({
15261560
count = 0;
15271561

15281562
function startPage(){
1529-
count = 0;
1563+
count = 0;
15301564
}
1531-
1565+
15321566
parser.addListener("startpage", startPage);
1533-
1567+
15341568
parser.addListener("import", function(){
15351569
count++;
15361570
});
15371571

15381572
parser.addListener("endstylesheet", function() {
15391573
if (count > MAX_IMPORT_COUNT) {
15401574
reporter.rollupError(
1541-
"Too many @import rules (" + count + "). IE6-9 supports up to 31 import per stylesheet.",
1575+
"Too many @import rules (" + count + "). IE6-9 supports up to 31 import per stylesheet.",
15421576
rule
15431577
);
15441578
}

dist/csslint-rhino.js

+41-7
Original file line numberDiff line numberDiff line change
@@ -6895,13 +6895,30 @@ var CSSLint = (function() {
68956895
var i = 0,
68966896
reporter,
68976897
lines,
6898+
allow = {},
68986899
report,
68996900
parser = new parserlib.css.Parser({ starHack: true, ieFilters: true,
69006901
underscoreHack: true, strict: false });
69016902

69026903
// normalize line endings
69036904
lines = text.replace(/\n\r?/g, "$split$").split("$split$");
69046905

6906+
// find 'allow' comments
6907+
CSSLint.Util.forEach(lines, function (line, lineno) {
6908+
var allowLine = line && line.match(/\/\*[ \t]*csslint[ \t]+allow:[ \t]*([^\*]*)\*\//i),
6909+
allowRules = allowLine && allowLine[1],
6910+
allowRuleset = {};
6911+
6912+
if (allowRules) {
6913+
allowRules.toLowerCase().split(",").forEach(function(allowRule){
6914+
allowRuleset[allowRule.trim()] = true;
6915+
});
6916+
if (Object.keys(allowRuleset).length > 0) {
6917+
allow[lineno + 1] = allowRuleset;
6918+
}
6919+
}
6920+
});
6921+
69056922
if (!ruleset) {
69066923
ruleset = this.getRuleset();
69076924
}
@@ -6912,7 +6929,7 @@ var CSSLint = (function() {
69126929
ruleset = applyEmbeddedRuleset(text, ruleset);
69136930
}
69146931

6915-
reporter = new Reporter(lines, ruleset);
6932+
reporter = new Reporter(lines, ruleset, allow);
69166933

69176934
ruleset.errors = 2; //always report parsing errors as errors
69186935
for (i in ruleset) {
@@ -6934,7 +6951,8 @@ var CSSLint = (function() {
69346951
report = {
69356952
messages : reporter.messages,
69366953
stats : reporter.stats,
6937-
ruleset : reporter.ruleset
6954+
ruleset : reporter.ruleset,
6955+
allow : reporter.allow
69386956
};
69396957

69406958
//sort by line numbers, rollups at the bottom
@@ -6968,7 +6986,7 @@ var CSSLint = (function() {
69686986
* @param {Object} ruleset The set of rules to work with, including if
69696987
* they are errors or warnings.
69706988
*/
6971-
function Reporter(lines, ruleset) {
6989+
function Reporter(lines, ruleset, allow) {
69726990
"use strict";
69736991

69746992
/**
@@ -7000,6 +7018,16 @@ function Reporter(lines, ruleset) {
70007018
* @type Object
70017019
*/
70027020
this.ruleset = ruleset;
7021+
7022+
/**
7023+
* Lines with specific rule messages to leave out of the report.
7024+
* @property allow
7025+
* @type Object
7026+
*/
7027+
this.allow = allow;
7028+
if(!this.allow) {
7029+
this.allow = {};
7030+
}
70037031
}
70047032

70057033
Reporter.prototype = {
@@ -7051,6 +7079,12 @@ Reporter.prototype = {
70517079
*/
70527080
report: function(message, line, col, rule) {
70537081
"use strict";
7082+
7083+
// Check if rule violation should be allowed
7084+
if (this.allow.hasOwnProperty(line) && this.allow[line].hasOwnProperty(rule.id)) {
7085+
return;
7086+
}
7087+
70547088
this.messages.push({
70557089
type : this.ruleset[rule.id] === 2 ? "error" : "warning",
70567090
line : line,
@@ -8219,19 +8253,19 @@ CSSLint.addRule({
82198253
count = 0;
82208254

82218255
function startPage(){
8222-
count = 0;
8256+
count = 0;
82238257
}
8224-
8258+
82258259
parser.addListener("startpage", startPage);
8226-
8260+
82278261
parser.addListener("import", function(){
82288262
count++;
82298263
});
82308264

82318265
parser.addListener("endstylesheet", function() {
82328266
if (count > MAX_IMPORT_COUNT) {
82338267
reporter.rollupError(
8234-
"Too many @import rules (" + count + "). IE6-9 supports up to 31 import per stylesheet.",
8268+
"Too many @import rules (" + count + "). IE6-9 supports up to 31 import per stylesheet.",
82358269
rule
82368270
);
82378271
}

dist/csslint-tests.js

+46-1
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,27 @@ function include(path, sandbox) {
245245
Assert.areEqual(2, result.ruleset["adjoining-classes"]);
246246
Assert.areEqual(1, result.ruleset["text-indent"]);
247247
Assert.areEqual(0, result.ruleset["box-sizing"]);
248+
},
249+
250+
"Allow statement on one line with one rule should be added to report": function(){
251+
var report = CSSLint.verify(".foo.bar{}\n.baz.qux{} /* csslint allow: box-sizing */\nquux.corge{}");
252+
Assert.isTrue(report.allow.hasOwnProperty("2"));
253+
Assert.isTrue(report.allow["2"].hasOwnProperty("box-sizing"));
254+
},
255+
256+
"Allow statement on one line with multiple rules should be added to report": function(){
257+
var report = CSSLint.verify(".foo.bar{}\n.baz.qux{} /* csslint allow: box-sizing, box-model */\nquux.corge{}");
258+
Assert.isTrue(report.allow.hasOwnProperty("2"));
259+
Assert.isTrue(report.allow["2"].hasOwnProperty("box-sizing"));
260+
Assert.isTrue(report.allow["2"].hasOwnProperty("box-model"));
261+
},
262+
263+
"Allow statements on multiple lines for different rules should be added to report": function(){
264+
var report = CSSLint.verify(".foo.bar{}\n.baz.qux{} /* csslint allow: box-sizing */\nquux.corge{}\ngrault.garply{} /* csslint allow: box-model */");
265+
Assert.isTrue(report.allow.hasOwnProperty("2"));
266+
Assert.isTrue(report.allow["2"].hasOwnProperty("box-sizing"));
267+
Assert.isTrue(report.allow.hasOwnProperty("4"));
268+
Assert.isTrue(report.allow["4"].hasOwnProperty("box-model"));
248269
}
249270

250271
}));
@@ -281,6 +302,30 @@ function include(path, sandbox) {
281302

282303
Assert.areEqual(1, reporter.messages.length);
283304
Assert.areEqual("error", reporter.messages[0].type);
305+
},
306+
307+
"Allow statement should drop message about specific rule on specific line but not other lines": function(){
308+
var reporter = new CSSLint._Reporter([], { "fake-rule": 1}, {"3": {"fake-rule": true}});
309+
reporter.report("Foo", 2, 1, { id: "fake-rule" });
310+
reporter.report("Bar", 3, 1, { id: "fake-rule" });
311+
312+
Assert.areEqual(1, reporter.messages.length);
313+
},
314+
315+
"Allow statement should drop message about specific rule on specific line but not other rules": function(){
316+
var reporter = new CSSLint._Reporter([], { "fake-rule": 1, "fake-rule2": 1}, {"3": {"fake-rule": true}});
317+
reporter.report("Foo", 3, 1, { id: "fake-rule" });
318+
reporter.report("Bar", 3, 1, { id: "fake-rule2" });
319+
320+
Assert.areEqual(1, reporter.messages.length);
321+
},
322+
323+
"Allow statement should drop messages about multiple rules on specific line": function(){
324+
var reporter = new CSSLint._Reporter([], { "fake-rule": 1, "fake-rule2": 1}, {"3": {"fake-rule": true, "fake-rule2": true}});
325+
reporter.report("Foo", 3, 1, { id: "fake-rule" });
326+
reporter.report("Bar", 3, 1, { id: "fake-rule2" });
327+
328+
Assert.areEqual(0, reporter.messages.length);
284329
}
285330

286331
}));
@@ -2437,7 +2482,7 @@ background: -o-linear-gradient(top, #1e5799 ,#2989d8 ,#207cca ,#7db9e8 );
24372482
YUITest.TestRunner.add(new YUITest.TestCase({
24382483

24392484
name: "Import IE Limit Rule Error",
2440-
2485+
24412486
"Using @import <= 31 times should not result in error": function(){
24422487

24432488
var result = CSSLint.verify(withinLimitCss, { "import-ie-limit": 1 });

0 commit comments

Comments
 (0)