Permalink
Browse files

Added CLI option for ignoring rules (fixes #231)

  • Loading branch information...
1 parent e025e5a commit d21546743d86cf1fc21df4e525f1a80671873a8a @nzakas nzakas committed Jul 23, 2012
Showing with 42 additions and 8 deletions.
  1. +23 −4 src/cli/common.js
  2. +19 −4 src/core/CSSLint.js
View
@@ -26,9 +26,8 @@ function cli(api){
* @param options {Object} The CLI options.
* @return {Object} A ruleset object.
*/
- function gatherRules(options){
- var ruleset,
- warnings = options.rules || options.warnings,
+ function gatherRules(options, ruleset){
+ var warnings = options.rules || options.warnings,
errors = options.errors;
if (warnings){
@@ -44,6 +43,24 @@ function cli(api){
ruleset[value] = 2;
});
}
+
+ return ruleset;
+ }
+
+ /**
+ * Filters out rules using the ignore command line option.
+ * @param options {Object} the CLI options
+ * @return {Object} A ruleset object.
+ */
+ function filterRules(options) {
+ var ignore = options.ignore,
+ ruleset = CSSLint.getRuleset();
+
+ if (ignore) {
+ ignore.split(",").forEach(function(value){
+ delete ruleset[value];
+ });
+ }
return ruleset;
}
@@ -68,7 +85,8 @@ function cli(api){
*/
function processFile(relativeFilePath, options) {
var input = api.readFile(relativeFilePath),
- result = CSSLint.verify(input, gatherRules(options)),
+ ruleset = filterRules(options),
+ result = CSSLint.verify(input, gatherRules(options, ruleset)),
formatter = CSSLint.getFormatter(options.format || "text"),
messages = result.messages || [],
output,
@@ -113,6 +131,7 @@ function cli(api){
" --quiet Only output when errors are present.",
" --errors=<rule[,rule]+> Indicate which rules to include as errors.",
" --warnings=<rule[,rule]+> Indicate which rules to include as warnings.",
+ " --ignore=<rule,[,rule]+> Indicate which rules to ignore completely.",
" --version Outputs the current version number."
].join("\n") + "\n");
}
View
@@ -45,6 +45,23 @@ var CSSLint = (function(){
return a.id > b.id ? 1 : 0;
});
};
+
+ /**
+ * Returns a ruleset configuration object with all current rules.
+ * @return A ruleset object.
+ * @method getRuleset
+ */
+ api.getRuleset = function() {
+ var ruleset = {},
+ i = 0,
+ len = rules.length;
+
+ while (i < len){
+ ruleset[rules[i++].id] = 1; //by default, everything is a warning
+ }
+
+ return ruleset;
+ };
//-------------------------------------------------------------------------
// Formatters
@@ -125,13 +142,11 @@ var CSSLint = (function(){
parser = new parserlib.css.Parser({ starHack: true, ieFilters: true,
underscoreHack: true, strict: false });
+ // normalize line endings
lines = text.replace(/\n\r?/g, "$split$").split('$split$');
if (!ruleset){
- ruleset = {};
- while (i < len){
- ruleset[rules[i++].id] = 1; //by default, everything is a warning
- }
+ ruleset = this.getRuleset();
}
reporter = new Reporter(lines, ruleset);

0 comments on commit d215467

Please sign in to comment.