Skip to content

Instantly share code, notes, and snippets.

@nzakas
Created February 9, 2012 17:03
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nzakas/1781185 to your computer and use it in GitHub Desktop.
Save nzakas/1781185 to your computer and use it in GitHub Desktop.
CSS Lint API
//include
var CSSLint = require("csslint").CSSLint;
/*
* Basic usage
* First argument is the CSS text.
* Second argument is the options object. Name is the ID of the rule (see wiki) set to
* either 1 for a warning or 2 for an error.
*/
var result = CSSLint.verify(".foo { }", { "compatible-vendor-prefixes": 1 }),
messages = result.messages;
/*
* Each object in the messages array has:
* - message - the actual warning text
* - evidence - the line of code that triggered the message
* - line - the line number
* - col - the column number
* - type - the type of message ("error" or "warning")
*/
messages.forEach(function (message, i) {
output = output + "\n\n" + shortFilename;
if (message.rollup) {
output += "\n" + (i+1) + ": " + message.type;
output += "\n" + message.message;
} else {
output += "\n" + (i+1) + ": " + message.type + " at line " + message.line + ", col " + message.col;
output += "\n" + message.message;
output += "\n" + message.evidence;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment