Skip to content

Commit c4560af

Browse files
committed
Merge pull request #441 from dashk/master
New rule to detect if a sheet has @import over 31 sheets in IE6-9
2 parents 9eefec2 + a0b1881 commit c4560af

File tree

2 files changed

+89
-0
lines changed

2 files changed

+89
-0
lines changed

src/rules/import-ie-limit.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Rule: IE6-9 supports up to 31 stylesheet import.
3+
* Reference:
4+
* http://blogs.msdn.com/b/ieinternals/archive/2011/05/14/internet-explorer-stylesheet-rule-selector-import-sheet-limit-maximum.aspx
5+
*/
6+
7+
CSSLint.addRule({
8+
9+
//rule information
10+
id: "import-ie-limit",
11+
name: "@import limit on IE6-IE9",
12+
desc: "IE6-9 supports up to 31 @import per stylesheet",
13+
browsers: "IE6, IE7, IE8, IE9",
14+
15+
//initialization
16+
init: function(parser, reporter){
17+
"use strict";
18+
var rule = this,
19+
MAX_IMPORT_COUNT = 31,
20+
count = 0;
21+
22+
function startPage(){
23+
count = 0;
24+
}
25+
26+
parser.addListener("startpage", startPage);
27+
28+
parser.addListener("import", function(){
29+
count++;
30+
});
31+
32+
parser.addListener("endstylesheet", function() {
33+
if (count > MAX_IMPORT_COUNT) {
34+
reporter.rollupError(
35+
"Too many @import rules (" + count + "). IE6-9 supports up to 31 import per stylesheet.",
36+
rule
37+
);
38+
}
39+
});
40+
}
41+
42+
});

tests/rules/import-ie-limit.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
(function(){
2+
"use strict";
3+
var Assert = YUITest.Assert,
4+
IMPORT_STATEMENT = "@import url('foo.css');",
5+
MAX_IMPORT_LIMIT = 31,
6+
withinLimitCss = "",
7+
exceedLimitCss = "",
8+
greatlyExceedLimitCss = "",
9+
i;
10+
11+
// Build CSS strings to be used in tests
12+
withinLimitCss = IMPORT_STATEMENT;
13+
14+
for (i = 0; i < MAX_IMPORT_LIMIT + 1; i++) {
15+
exceedLimitCss += IMPORT_STATEMENT;
16+
}
17+
18+
for (i = 0; i < MAX_IMPORT_LIMIT + 100; i++) {
19+
greatlyExceedLimitCss += IMPORT_STATEMENT;
20+
}
21+
22+
YUITest.TestRunner.add(new YUITest.TestCase({
23+
24+
name: "Import IE Limit Rule Error",
25+
26+
"Using @import <= 31 times should not result in error": function(){
27+
28+
var result = CSSLint.verify(withinLimitCss, { "import-ie-limit": 1 });
29+
Assert.areEqual(0, result.messages.length);
30+
},
31+
32+
"Using @import > 31 times should result in error": function(){
33+
var result = CSSLint.verify(exceedLimitCss, { "import-ie-limit": 1 });
34+
Assert.areEqual(1, result.messages.length);
35+
Assert.areEqual("error", result.messages[0].type);
36+
Assert.areEqual("Too many @import rules (32). IE6-9 supports up to 31 import per stylesheet.", result.messages[0].message);
37+
},
38+
39+
"Using @import > 31 times repeatedly should result in a single error": function(){
40+
var result = CSSLint.verify(greatlyExceedLimitCss, { "import-ie-limit": 1 });
41+
Assert.areEqual(1, result.messages.length);
42+
Assert.areEqual("error", result.messages[0].type);
43+
Assert.areEqual("Too many @import rules (131). IE6-9 supports up to 31 import per stylesheet.", result.messages[0].message);
44+
}
45+
}));
46+
47+
})();

0 commit comments

Comments
 (0)