Skip to content

Commit 50ea8a7

Browse files
dashkKenny Wong
authored andcommitted
Updated patch per feedback from @pomeh
1 parent 1a1159d commit 50ea8a7

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

src/rules/import-ie-limit.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,16 @@ CSSLint.addRule({
2626

2727
parser.addListener("import", function(event){
2828
count++;
29+
});
30+
31+
parser.addListener("endstylesheet", function() {
2932
if (count > MAX_IMPORT_COUNT) {
30-
reporter.error("Stylesheet contains > 31 @import. This is not supported in IE6-9.", event.line, event.col, rule);
33+
reporter.rollupError(
34+
"Too many @import rules (" + count + "). IE6-9 supports up to 31 import per stylesheet.",
35+
rule
36+
);
3137
}
3238
});
33-
3439
}
3540

3641
});

tests/rules/import-ie-limit.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
MAX_IMPORT_LIMIT = 31,
77
withinLimitCss = "",
88
exceedLimitCss = "",
9+
greatlyExceedLimitCss = "",
910
i;
1011

1112
// Build CSS strings to be used in tests
@@ -15,21 +16,32 @@
1516
exceedLimitCss += IMPORT_STATEMENT;
1617
}
1718

19+
for (i = 0; i < MAX_IMPORT_LIMIT + 100; i++) {
20+
greatlyExceedLimitCss += IMPORT_STATEMENT;
21+
}
22+
1823
YUITest.TestRunner.add(new YUITest.TestCase({
1924

2025
name: "Import IE Limit Rule Error",
2126

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

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

2833
"Using @import > 31 times should result in error": function(){
2934
var result = CSSLint.verify(exceedLimitCss, { "import-ie-limit": 1 });
3035
Assert.areEqual(1, result.messages.length);
3136
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);
37+
Assert.areEqual("Too many @import rules (32). IE6-9 supports up to 31 import per stylesheet.", result.messages[0].message);
38+
},
39+
40+
"Using @import > 31 times repeatedly should result in a single error": function(){
41+
var result = CSSLint.verify(greatlyExceedLimitCss, { "import-ie-limit": 1 });
42+
Assert.areEqual(1, result.messages.length);
43+
Assert.areEqual("error", result.messages[0].type);
44+
Assert.areEqual("Too many @import rules (131). IE6-9 supports up to 31 import per stylesheet.", result.messages[0].message);
3345
}
3446
}));
3547

0 commit comments

Comments
 (0)