Fix invalid XML from the CLI xml reporter (#217)

* Remove javascriptExecutionTree from the xml output
* Change JSON structure for offenders classified by url
* Remove special chars from XML output
This commit is contained in:
Gaël Métais
2016-12-28 23:51:18 +08:00
committed by GitHub
parent bdf5f82959
commit 4911d61d78
5 changed files with 149204 additions and 11 deletions
+21 -2
View File
@@ -84,8 +84,27 @@ if (cli.flags.reporter && cli.flags.reporter !== 'json' && cli.flags.reporter !=
debug('Success');
switch(cli.flags.reporter) {
case 'xml':
var serializer = new EasyXml();
console.log(serializer.render(data));
var serializer = new EasyXml({
manifest: true
});
// Remove some heavy parts of the results object
delete data.toolsResults;
delete data.javascriptExecutionTree;
var xmlOutput = serializer.render(data);
// Remove special chars from XML tags: # [ ]
xmlOutput = xmlOutput.replace(/<([^>]*)#([^>]*)>/g, '<$1>');
xmlOutput = xmlOutput.replace(/<([^>]*)\[([^>]*)>/g, '<$1>');
xmlOutput = xmlOutput.replace(/<([^>]*)\]([^>]*)>/g, '<$1>');
// Remove special chars from text content: \n \0
xmlOutput = xmlOutput.replace(/(<[a-zA-Z]*>[^<]*)\n([^<]*<\/[a-zA-Z]*>)/g, '$1$2');
xmlOutput = xmlOutput.replace(/\0/g, '');
xmlOutput = xmlOutput.replace(/\uFFFF/g, '');
console.log(xmlOutput);
break;
default:
console.log(JSON.stringify(data, null, 2));
+3 -3
View File
@@ -167,12 +167,12 @@
</div>
</div>
<div ng-repeat="(file, fileDetails) in rule.offendersObj.byFile track by $index">
<div ng-repeat="fileDetails in rule.offendersObj.byFile track by $index">
<h3>
<ng-pluralize count="fileDetails.count" when="{'one': '1 offender', 'other': '{} offenders'}"></ng-pluralize>
in
<url-link ng-if="file !== 'Inline CSS'" url="file" max-length="80"></url-link>
<span ng-if="file === 'Inline CSS'">inline CSS</span>
<url-link ng-if="fileDetails.url !== 'Inline CSS'" url="fileDetails.url" max-length="80"></url-link>
<span ng-if="fileDetails.url === 'Inline CSS'">inline CSS</span>
</h3>
<div class="offendersTable">
+13 -6
View File
@@ -207,24 +207,31 @@ var OffendersHelpers = function() {
};
this.orderByFile = function(offenders) {
var byFile = {};
var byFileObj = {};
offenders.forEach(function(offender) {
var file = offender.file || 'Inline CSS';
delete offender.file;
if (!byFile[file]) {
byFile[file] = {
if (!byFileObj[file]) {
byFileObj[file] = {
url: file,
count: 0,
offenders: []
};
}
byFile[file].count ++;
byFile[file].offenders.push(offender);
byFileObj[file].count ++;
byFileObj[file].offenders.push(offender);
});
return {byFile: byFile};
// Transform object into array
var byFileArray = [];
for (var file in byFileObj) {
byFileArray.push(byFileObj[file]);
}
return {byFile: byFileArray};
};
};
+143985
View File
File diff suppressed because it is too large Load Diff
+5182
View File
File diff suppressed because it is too large Load Diff