public
Created

CSS Lint API

  • Download Gist
csslint-api.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
//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;
}
});

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.