-
Notifications
You must be signed in to change notification settings - Fork 482
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Sergey Chernyshev
committed
Feb 25, 2016
1 parent
9c62146
commit 503b16a
Showing
2 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* global JSON */ | ||
|
||
CSSLint.addFormatter({ | ||
//format information | ||
id: "json", | ||
name: "CSSLint JSON format", | ||
json: [], | ||
options: {}, | ||
|
||
/** | ||
* Return content to be printed before all file results. | ||
* @return {String} to prepend before all results | ||
*/ | ||
startFormat: function() { | ||
"use strict"; | ||
return ""; | ||
}, | ||
|
||
/** | ||
* Return full JSON | ||
* @return {String} to append after all results | ||
*/ | ||
endFormat: function() { | ||
"use strict"; | ||
return JSON.stringify(this.json); | ||
}, | ||
|
||
/** | ||
* 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} (UNUSED for now) specifies special handling of output | ||
* @return {String} output for results | ||
*/ | ||
formatResults: function(results, filename, options) { | ||
"use strict"; | ||
options = options || {}; | ||
|
||
if (results.messages.length > 0) { | ||
this.json.push({ | ||
filename: filename, | ||
results: results | ||
}); | ||
} | ||
return ""; | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
(function() { | ||
"use strict"; | ||
var Assert = YUITest.Assert; | ||
|
||
YUITest.TestRunner.add(new YUITest.TestCase({ | ||
|
||
name: "JSON formatter", | ||
|
||
"File with no problems should return empty string": function() { | ||
var result = { | ||
messages: [], | ||
stats: [] | ||
}, | ||
actual = CSSLint.getFormatter("json").formatResults(result, "path/to/FILE", { | ||
fullPath: "/absolute/path/to/FILE" | ||
}); | ||
Assert.areEqual("", actual); | ||
}, | ||
|
||
"Files with problems should list them": function() { | ||
var result = { | ||
messages: [{ | ||
type: "warning", | ||
line: 1, | ||
col: 1, | ||
message: "BOGUS", | ||
evidence: "ALSO BOGUS", | ||
rule: [] | ||
}, { | ||
type: "error", | ||
line: 2, | ||
col: 1, | ||
message: "BOGUS", | ||
evidence: "ALSO BOGUS", | ||
rule: [] | ||
}], | ||
stats: [] | ||
}; | ||
|
||
/*jshint -W108 */ | ||
var expected = '[{"filename":"path/to/FILE","results":{"messages":[{"type":"warning","line":1,"col":1,"message":"BOGUS","evidence":"ALSO BOGUS","rule":[]},{"type":"error","line":2,"col":1,"message":"BOGUS","evidence":"ALSO BOGUS","rule":[]}],"stats":[]}}]'; | ||
|
||
var formatter = CSSLint.getFormatter("json"); | ||
|
||
var actual = formatter.startFormat() + formatter.formatResults(result, "path/to/FILE", { | ||
fullPath: "/absolute/path/to/FILE" | ||
}) + formatter.endFormat(); | ||
|
||
Assert.areEqual(expected, actual); | ||
} | ||
|
||
})); | ||
|
||
})(); |