Skip to content

Commit c03333a

Browse files
committed
Updated the selector-max and selector-max-approaching rules to apply to CSS selectors not just CSS rules.
1 parent 73ee863 commit c03333a

File tree

4 files changed

+121
-44
lines changed

4 files changed

+121
-44
lines changed

src/rules/selector-max-approaching.js

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,23 @@ CSSLint.addRule({
66

77
//rule information
88
id: "selector-max-approaching",
9-
name: "Warn when approaching the 4095 limit for IE",
10-
desc: "Will warn when selector count is >= 3800 rules.",
9+
name: "Warn when approaching the 4095 selector limit for IE",
10+
desc: "Will warn when selector count is >= 3800 selectors.",
1111
browsers: "IE",
1212

1313
//initialization
14-
init: function(parser, reporter){
15-
var rule = this,
16-
count = 0;
14+
init: function(parser, reporter) {
15+
var rule = this, count = 0;
1716

18-
parser.addListener('startrule',function(event){
19-
count++;
20-
21-
});
17+
parser.addListener('startrule', function(event) {
18+
count += event.selectors.length;
19+
});
2220

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-
}
21+
parser.addListener("endstylesheet", function() {
22+
if (count >= 3800) {
23+
reporter.report("You have " + count + " selectors. Internet Explorer supports a maximum of 4095 selectors per stylesheet. Consider refactoring.",0,0,rule);
24+
}
2725
});
28-
}
26+
}
2927

3028
});

src/rules/selector-max.js

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,23 @@ CSSLint.addRule({
66

77
//rule information
88
id: "selector-max",
9-
name: "Error when past the 4095 limit for IE",
9+
name: "Error when past the 4095 selector limit for IE",
1010
desc: "Will error when selector count is > 4095.",
1111
browsers: "IE",
1212

1313
//initialization
1414
init: function(parser, reporter){
15-
var rule = this,
16-
count = 0;
15+
var rule = this, count = 0;
1716

18-
parser.addListener('startrule',function(event){
19-
count++;
20-
});
17+
parser.addListener('startrule',function(event) {
18+
count += event.selectors.length;
19+
});
2120

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-
}
21+
parser.addListener("endstylesheet", function() {
22+
if (count > 4095) {
23+
reporter.report("You have " + count + " selectors. Internet Explorer supports a maximum of 4095 selectors per stylesheet. Consider refactoring.",0,0,rule);
24+
}
25+
});
26+
}
2827

2928
});

tests/rules/selector-max-approaching.js

Lines changed: 52 additions & 7 deletions
Large diffs are not rendered by default.

tests/rules/selector-max.js

Lines changed: 46 additions & 11 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)