Skip to content

Commit d215467

Browse files
committed
Added CLI option for ignoring rules (fixes #231)
1 parent e025e5a commit d215467

File tree

2 files changed

+42
-8
lines changed

2 files changed

+42
-8
lines changed

src/cli/common.js

+23-4
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@ function cli(api){
2626
* @param options {Object} The CLI options.
2727
* @return {Object} A ruleset object.
2828
*/
29-
function gatherRules(options){
30-
var ruleset,
31-
warnings = options.rules || options.warnings,
29+
function gatherRules(options, ruleset){
30+
var warnings = options.rules || options.warnings,
3231
errors = options.errors;
3332

3433
if (warnings){
@@ -44,6 +43,24 @@ function cli(api){
4443
ruleset[value] = 2;
4544
});
4645
}
46+
47+
return ruleset;
48+
}
49+
50+
/**
51+
* Filters out rules using the ignore command line option.
52+
* @param options {Object} the CLI options
53+
* @return {Object} A ruleset object.
54+
*/
55+
function filterRules(options) {
56+
var ignore = options.ignore,
57+
ruleset = CSSLint.getRuleset();
58+
59+
if (ignore) {
60+
ignore.split(",").forEach(function(value){
61+
delete ruleset[value];
62+
});
63+
}
4764

4865
return ruleset;
4966
}
@@ -68,7 +85,8 @@ function cli(api){
6885
*/
6986
function processFile(relativeFilePath, options) {
7087
var input = api.readFile(relativeFilePath),
71-
result = CSSLint.verify(input, gatherRules(options)),
88+
ruleset = filterRules(options),
89+
result = CSSLint.verify(input, gatherRules(options, ruleset)),
7290
formatter = CSSLint.getFormatter(options.format || "text"),
7391
messages = result.messages || [],
7492
output,
@@ -113,6 +131,7 @@ function cli(api){
113131
" --quiet Only output when errors are present.",
114132
" --errors=<rule[,rule]+> Indicate which rules to include as errors.",
115133
" --warnings=<rule[,rule]+> Indicate which rules to include as warnings.",
134+
" --ignore=<rule,[,rule]+> Indicate which rules to ignore completely.",
116135
" --version Outputs the current version number."
117136
].join("\n") + "\n");
118137
}

src/core/CSSLint.js

+19-4
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,23 @@ var CSSLint = (function(){
4545
return a.id > b.id ? 1 : 0;
4646
});
4747
};
48+
49+
/**
50+
* Returns a ruleset configuration object with all current rules.
51+
* @return A ruleset object.
52+
* @method getRuleset
53+
*/
54+
api.getRuleset = function() {
55+
var ruleset = {},
56+
i = 0,
57+
len = rules.length;
58+
59+
while (i < len){
60+
ruleset[rules[i++].id] = 1; //by default, everything is a warning
61+
}
62+
63+
return ruleset;
64+
};
4865

4966
//-------------------------------------------------------------------------
5067
// Formatters
@@ -125,13 +142,11 @@ var CSSLint = (function(){
125142
parser = new parserlib.css.Parser({ starHack: true, ieFilters: true,
126143
underscoreHack: true, strict: false });
127144

145+
// normalize line endings
128146
lines = text.replace(/\n\r?/g, "$split$").split('$split$');
129147

130148
if (!ruleset){
131-
ruleset = {};
132-
while (i < len){
133-
ruleset[rules[i++].id] = 1; //by default, everything is a warning
134-
}
149+
ruleset = this.getRuleset();
135150
}
136151

137152
reporter = new Reporter(lines, ruleset);

0 commit comments

Comments
 (0)