Skip to content

Commit 1a1159d

Browse files
dashkKenny Wong
authored andcommitted
Add new rule to detect if number of @import has exceeded the limit in IE6-9
1 parent 9eefec2 commit 1a1159d

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

src/rules/import-ie-limit.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
/*global CSSLint*/
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+
var rule = this,
18+
MAX_IMPORT_COUNT = 31,
19+
count = 0;
20+
21+
function startPage(event){
22+
count = 0;
23+
}
24+
25+
parser.addListener("startpage", startPage);
26+
27+
parser.addListener("import", function(event){
28+
count++;
29+
if (count > MAX_IMPORT_COUNT) {
30+
reporter.error("Stylesheet contains > 31 @import. This is not supported in IE6-9.", event.line, event.col, rule);
31+
}
32+
});
33+
34+
}
35+
36+
});

tests/rules/import-ie-limit.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
(function(){
2+
3+
/*global YUITest, CSSLint*/
4+
var Assert = YUITest.Assert,
5+
IMPORT_STATEMENT = "@import url('foo.css');",
6+
MAX_IMPORT_LIMIT = 31,
7+
withinLimitCss = "",
8+
exceedLimitCss = "",
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+
YUITest.TestRunner.add(new YUITest.TestCase({
19+
20+
name: "Import IE Limit Rule Error",
21+
22+
"Using @import <= 31 times should not result in error": function(){
23+
24+
var result = CSSLint.verify(withinLimitCss, { "import-ie-limit": 0 });
25+
Assert.areEqual(0, result.messages.length);
26+
},
27+
28+
"Using @import > 31 times should result in error": function(){
29+
var result = CSSLint.verify(exceedLimitCss, { "import-ie-limit": 1 });
30+
Assert.areEqual(1, result.messages.length);
31+
Assert.areEqual("error", result.messages[0].type);
32+
Assert.areEqual("Stylesheet contains > 31 @import. This is not supported in IE6-9.", result.messages[0].message);
33+
}
34+
}));
35+
36+
})();

0 commit comments

Comments
 (0)