CSSLint / csslint

Automated linting of Cascading Stylesheets
http://csslint.net
Other
4.77k stars 483 forks source link

Formatters API issue with multi-item formats #645

Open sergeychernyshev opened 8 years ago

sergeychernyshev commented 8 years ago

It seems that there is an issue with how CSSLint handles formatting when format for multiple files can't be combined by simple concatenation of results for individual file.

I came across the issue when developing formatter for JSON, but it can apply to other formatters as well - in fact it's just a lucky chance that no previous formatters had this issue.

Essentially, in JSON, single file result is an object like so:

{messages: [{type: "warning", line: 1, col: 1, message: "BOGUS", evidence: "ALSO BOGUS", rule: []}], stats: []}

But multiple results must be wrapped in square brackets and separated by commas like so:

[
{messages: [{type: "warning", line: 1, col: 1, message: "BOGUS1", evidence: "ALSO BOGUS1", rule: []}], stats: []},
{messages: [{type: "warning", line: 2, col: 1, message: "BOGUS2", evidence: "ALSO BOGUS2", rule: []}], stats: []},
{messages: [{type: "warning", line: 3, col: 1, message: "BOGUS3", evidence: "ALSO BOGUS3", rule: []}], stats: []}
]

or even more complex object indicating a file name, for example.

Unfortunately, it seems that the tool is simply looping through the files and prints out the result on each pass effectively concatenating the results.

It might be a better idea to allow formatters format multiple entries through a separate call like formatMultipleResults()

I might take a stab at it while updating JSON formatter.

frvge commented 8 years ago

Would be nice, yes.