Skip to content

Commit 8182d9d

Browse files
committed
Rules and test for the IE max selector count warning. There are two rules one that checks for crossing 3800 rules and one that checks for crossing the 4095 limit.
1 parent 627ea5a commit 8182d9d

File tree

2 files changed

+88
-0
lines changed

2 files changed

+88
-0
lines changed

src/rules/selector-max.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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: "All",
12+
13+
//initialization
14+
init: function(parser, reporter){
15+
var rule = this,
16+
count = 0,
17+
notFired = true;
18+
19+
parser.addListener('startrule',function(event){
20+
count++;
21+
if(count >= 3800 && notFired){
22+
notFired=false;
23+
var selectors = event.selectors;
24+
reporter.report("Rule is the number 3800 and approaching the 4095 IE limit.", selectors[0].line, selectors[0].col, rule);
25+
}
26+
});
27+
}
28+
29+
});
30+
31+
32+
33+
CSSLint.addRule({
34+
35+
//rule information
36+
id: "selector-max",
37+
name: "Error when past the 4095 limit for IE",
38+
desc: "Will error when selector count is > 4095.",
39+
browsers: "All",
40+
41+
//initialization
42+
init: function(parser, reporter){
43+
var rule = this,
44+
count = 0,
45+
notFired = true;
46+
47+
parser.addListener('startrule',function(event){
48+
count++;
49+
if(count >= 4096 && notFired){
50+
notFired=false;
51+
var selectors = event.selectors;
52+
reporter.report("Rule is the number 4096 and past the 4095 IE limit.", selectors[0].line, selectors[0].col, rule);
53+
}
54+
});
55+
}
56+
57+
});

tests/rules/selector-max.js

Lines changed: 31 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)