Skip to content

Commit 43cee88

Browse files
committed
Merge pull request #304 from beckje01/tooManyRules
Rules and test for the IE max selector count warning.
2 parents c6d79d2 + c669f6f commit 43cee88

File tree

4 files changed

+106
-0
lines changed

4 files changed

+106
-0
lines changed

src/rules/selector-max-approaching.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Rule: Warn people with approaching the IE 4095 limit
3+
*/
4+
/*global CSSLint*/
5+
CSSLint.addRule({
6+
7+
//rule information
8+
id: "selector-max-approaching",
9+
name: "Warn when approaching the 4095 limit for IE",
10+
desc: "Will warn when selector count is >= 3800 rules.",
11+
browsers: "IE",
12+
13+
//initialization
14+
init: function(parser, reporter){
15+
var rule = this,
16+
count = 0;
17+
18+
parser.addListener('startrule',function(event){
19+
count++;
20+
21+
});
22+
23+
parser.addListener("endstylesheet", function(){
24+
if(count >= 3800){
25+
reporter.report("You have "+count+" rules. Internet Explorer supports a maximum of 4095 rules. Consider refactoring.",0,0,rule);
26+
}
27+
});
28+
}
29+
30+
});

src/rules/selector-max.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Rule: Warn people past the IE 4095 limit
3+
*/
4+
/*global CSSLint*/
5+
CSSLint.addRule({
6+
7+
//rule information
8+
id: "selector-max",
9+
name: "Error when past the 4095 limit for IE",
10+
desc: "Will error when selector count is > 4095.",
11+
browsers: "IE",
12+
13+
//initialization
14+
init: function(parser, reporter){
15+
var rule = this,
16+
count = 0;
17+
18+
parser.addListener('startrule',function(event){
19+
count++;
20+
});
21+
22+
parser.addListener("endstylesheet", function(){
23+
if(count>4095){
24+
reporter.report("You have "+count+" rules. Internet Explorer supports a maximum of 4095 rules. All additional rules will be ignored by IE. Consider refactoring.",0,0,rule);
25+
}
26+
});
27+
}
28+
29+
});

tests/rules/selector-max-approaching.js

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/rules/selector-max.js

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)