stubbornella/csslint — Issue #199: Provide a formatter that produces messages like a C-compiler
Author: DinoChiesa
Created: 2011-10-20 02:34:47+00:00
State: open

Something like this:

```javascript
CSSLint.addFormatter({
//format information
id: "compiler",
name: "plaintext compiler-like output",

/**
* Return content to be printed before all file results.
* @return {String} to prepend before all results
*/
startFormat: function() {
return "";
},

/**
* Return content to be printed after all file results.
* @return {String} to append after all results
*/
endFormat: function() {
return "";
},

/**
* Given CSS Lint results for a file, return output for this format.
* @param results {Object} with error and warning messages
* @param filename {String} relative file path
* @param options {Object} (Optional) specifies special handling of output
* @return {String} output for results
*/
formatResults: function(results, filename, options) {
var messages = results.messages,
output = "";
options = options || {};

if (messages.length === 0) {
return options.quiet ? "" : "\n\ncsslint: No errors in " + filename + ".";
}

//output = "csslint: There are " + messages.length + " problems in " + filename + ".";
output = "\nCSSLINT";
var pos = filename.lastIndexOf("/"),
shortFilename = filename;

if (pos === -1){
pos = filename.lastIndexOf("\\");
}
if (pos > -1){
shortFilename = filename.substring(pos+1);
}

messages.forEach(function (message, i) {
var thisMsg = "\n" + filename;

if (message.rollup) {
} else {
thisMsg += "(" + message.line + "," + message.col + ") CSSLINT: " + message.type + ": " + message.message;
thisMsg += "\n" + message.evidence;
output += thisMsg;
}
});

return output;
}
});
```

The output is like this :

CSSLINT
basic.css(5,1) CSSLINT:warning: Heading (h1) has already been defined.
h1 { font-size: 20pt }
basic.css(6,1) CSSLINT:warning: Heading (h2) has already been defined.
h2 { font-size: 16pt; color: navy }
basic.css(7,1) CSSLINT:warning: Heading (h3) has already been defined.
h3 { font-size: 14pt; color: #483d8b }
basic.css(8,1) CSSLINT:warning: Heading (h4) has already been defined.
h4 { font-size: 12pt; font-weight:bold; color:#C71585; margin-bottom:2px; }
basic.css(9,1) CSSLINT:warning: Heading (h5) has already been defined.
h5,h6 { font-size: 10pt }
basic.css(9,4) CSSLINT:warning: Heading (h6) has already been defined.
h5,h6 { font-size: 10pt }
basic.css(11,1) CSSLINT:warning: Element (td.head) is overqualified, just use .head without element name.
td.head { font-size: 12pt; color: #c71585; font-weight: bold; }
basic.css(12,52) CSSLINT:error: Unknown property 'bgcolor'.
th { font-weight: bold; color: #FCFCFC; bgcolor:#C0C0C0 }