This repository has been archived by the owner on Sep 17, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathxml.js
57 lines (50 loc) · 1.39 KB
/
xml.js
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
* Nodelint XML reporter
*
* This reporter produces XML that can be automatically recognised by
* Hudson Violations Plugin http://wiki.hudson-ci.org/display/HUDSON/Violations+Plugin
*
* Released into the Public Domain by tav <[email protected]>
* See the README.md for full credits of the awesome contributors!
*/
/**
* Module dependencies
*/
var
path = require('path'),
util = require('util');
/**
* Reporter info string
*/
exports.info = "XML reporter";
function escape(str) {
return (str) ? str
.replace(/&/g, '&')
.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/"/g, '"')
: '';
}
/**
* Report linting results to the command-line.
*
* @api public
*
* @param {Array} results
*/
exports.report = function report(results) {
var
i, error, len, file,
dir = process.cwd(),
xml = '<?xml version="1.0" encoding="UTF-8" ?>\n<jslint>\n';
for (i = 0, len = results.length; i < len; i += 1) {
file = path.resolve(dir, results[i].file);
error = results[i].error;
xml += '\t<file name="' + file + '">\n' +
'\t\t<issue char="' + error.character + '" evidence="' + escape(error.evidence || '') +
'" line="' + error.line + '" reason="' + escape(error.reason) + '"/>\n' +
'\t</file>\n';
}
xml += '</jslint>';
util.puts(xml);
};