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
42 changes: 42 additions & 0 deletions src/rules/import-ie-limit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Rule: IE6-9 supports up to 31 stylesheet import.
* Reference:
* http://blogs.msdn.com/b/ieinternals/archive/2011/05/14/internet-explorer-stylesheet-rule-selector-import-sheet-limit-maximum.aspx
*/

CSSLint.addRule({

//rule information
id: "import-ie-limit",
name: "@import limit on IE6-IE9",
desc: "IE6-9 supports up to 31 @import per stylesheet",
browsers: "IE6, IE7, IE8, IE9",

//initialization
init: function(parser, reporter){
"use strict";
var rule = this,
MAX_IMPORT_COUNT = 31,
count = 0;

function startPage(){
count = 0;
}

parser.addListener("startpage", startPage);

parser.addListener("import", function(){
count++;
});

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

});
47 changes: 47 additions & 0 deletions tests/rules/import-ie-limit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
(function(){
"use strict";
var Assert = YUITest.Assert,
IMPORT_STATEMENT = "@import url('foo.css');",
MAX_IMPORT_LIMIT = 31,
withinLimitCss = "",
exceedLimitCss = "",
greatlyExceedLimitCss = "",
i;

// Build CSS strings to be used in tests
withinLimitCss = IMPORT_STATEMENT;

for (i = 0; i < MAX_IMPORT_LIMIT + 1; i++) {
exceedLimitCss += IMPORT_STATEMENT;
}

for (i = 0; i < MAX_IMPORT_LIMIT + 100; i++) {
greatlyExceedLimitCss += IMPORT_STATEMENT;
}

YUITest.TestRunner.add(new YUITest.TestCase({

name: "Import IE Limit Rule Error",

"Using @import <= 31 times should not result in error": function(){

var result = CSSLint.verify(withinLimitCss, { "import-ie-limit": 1 });
Assert.areEqual(0, result.messages.length);
},

"Using @import > 31 times should result in error": function(){
var result = CSSLint.verify(exceedLimitCss, { "import-ie-limit": 1 });
Assert.areEqual(1, result.messages.length);
Assert.areEqual("error", result.messages[0].type);
Assert.areEqual("Too many @import rules (32). IE6-9 supports up to 31 import per stylesheet.", result.messages[0].message);
},

"Using @import > 31 times repeatedly should result in a single error": function(){
var result = CSSLint.verify(greatlyExceedLimitCss, { "import-ie-limit": 1 });
Assert.areEqual(1, result.messages.length);
Assert.areEqual("error", result.messages[0].type);
Assert.areEqual("Too many @import rules (131). IE6-9 supports up to 31 import per stylesheet.", result.messages[0].message);
}
}));

})();