Skip to content

Commit e58fed3

Browse files
committed
Adding ability to pass rules-max limit using cli
1 parent 7b73721 commit e58fed3

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

src/cli/common.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ function cli(api) {
2020
"exclude-list": { "format" : "<file|dir[,file|dir]+>", "description" : "Indicate which files/directories to exclude from being linted." },
2121
"config" : { "format" : "<file>", "description" : "Reads csslint options from specified file." },
2222
"version" : { "format" : "", "description" : "Outputs the current version number." },
23-
"name-pattern": { "format" : "<pattern>", "description" : "Indicate which pattern naming should follow." }
23+
"name-pattern": { "format" : "<pattern>", "description" : "Indicate which pattern naming should follow." },
24+
"max-rules" : { "format" : "<count>", "description" : "The maximum number of rules allowed in a stylesheet." }
2425
};
2526

2627
//-------------------------------------------------------------------------

src/rules/rules-max.js

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

77
// rule information
88
id: "rules-max",
9-
name: "Warn when 500+ rules are present",
10-
desc: "Will warn when the rule count in a stylesheet crosses the 500 threshold.",
11-
browsers: "IE",
9+
name: "Warn when too many rules are present",
10+
desc: "Will warn when the rule count in a stylesheet crosses the limit specified.",
11+
browsers: "All",
1212

1313
// initialization
14-
init: function(parser, reporter) {
14+
init: function(parser, reporter, options) {
1515
"use strict";
16-
var rule = this, ruleCount = 0, MAX_RULES = 499;
16+
var rule = this,
17+
ruleCount = 0,
18+
limit = options ? options["max-rules"] : 0;
19+
20+
limit = limit || 0;
1721

1822
parser.addListener("startrule", function() {
1923
ruleCount += 1;
2024
});
2125

2226
parser.addListener("endstylesheet", function() {
23-
if (ruleCount > MAX_RULES) {
27+
if (limit && limit < ruleCount) {
2428
reporter.report("There are too many rules (" + ruleCount + ") in the stylesheet.", 0, 0, rule);
2529
}
2630
});

tests/rules/rules-max.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@
3939
Assert.areEqual(0, result.messages.length);
4040
},
4141

42-
"Using 500 or more rules should result in a warning": function() {
43-
var result = CSSLint.verify(this.cssB, { "rules-max": 1 });
42+
"Using more rules than the limit should result in a warning": function() {
43+
var result = CSSLint.verify(this.cssB, { "rules-max": 1 }, { "max-rules": MAX_RULES });
4444

4545
Assert.areEqual(1, result.messages.length);
4646
Assert.areEqual("warning", result.messages[0].type);

0 commit comments

Comments
 (0)