Skip to content

Commit 17cfb23

Browse files
committed
Merge pull request #317 from philipwalton/selector-max
Fixed the selector max and selector max approaching rules
2 parents fb58a8e + d70202b commit 17cfb23

File tree

5 files changed

+123
-45
lines changed

5 files changed

+123
-45
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ CSSLint is a tool to help point out problems with your CSS code. It does basic s
2525
1. Cillian de Róiste, https://plus.google.com/116480676247600483573/posts (Node CLI fixes)
2626
1. Damien Sennm, https://github.com/topaxi (README fixes)
2727
1. Jonathan Barnett, http://twitter.com/indieisaconcept (JUnit formatter)
28-
1. Zach Leatherman, http://www.zachleat.com/ (bug fixes)
28+
1. Zach Leatherman, http://www.zachleat.com/ (bug fixes)
29+
1. Philip Walton, http://philipwalton.com (Rules fixes, bug fixes)

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)