Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(report): show source code snippets for violations #134

Merged
merged 1 commit into from
Dec 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
feat(report): show source code snippets for violations
- add a new `html` property to the `earl:result` object
- render the snippet in the "Location" column (only if
  a snippet is available)

Fixes #82
  • Loading branch information
rdeltour committed Dec 22, 2017
commit df21d2fd3870394dc1ba01d4fbc22404c854bbeb
1 change: 1 addition & 0 deletions packages/ace-report-axe/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ function axe2ace(spineItem, axeResults) {
new builders.ResultBuilder('fail')
.withDescription(node.failureSummary)
.withPointer(node.target, node.targetCFI)
.withHTML(node.html)
.build())
.build()));
});
Expand Down
1 change: 1 addition & 0 deletions packages/ace-report/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"license": "MIT",
"main": "lib/index.js",
"dependencies": {
"escape-html": "^1.0.3",
"fs-extra": "^4.0.2",
"handlebars": "^4.0.11",
"winston": "^2.4.0"
Expand Down
4 changes: 4 additions & 0 deletions packages/ace-report/src/generate-html-report.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

const escape = require('escape-html');
const handlebars = require('handlebars');
const fs = require('fs');
const path = require('path');
Expand Down Expand Up @@ -150,6 +151,9 @@ function createFlatListOfViolations(violations) {
if (item["earl:result"]["earl:pointer"]) {
obj.location += "#epubcfi(" + item["earl:result"]["earl:pointer"]["cfi"] + ")";
}
if (item["earl:result"]["html"]) {
obj.html = escape(item["earl:result"]["html"]);
}
flatData.push(obj);
});
});
Expand Down
4 changes: 4 additions & 0 deletions packages/ace-report/src/report-builders.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ class ResultBuilder {
this._json['dct:description'] = description;
return this;
}
withHTML(html) {
this._json['html'] = html;
return this;
}
withPointer(css, cfi) {
this._json['earl:pointer'] = { cfi, css };
return this;
Expand Down
14 changes: 14 additions & 0 deletions packages/ace-report/src/resources/report-template.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@
font-size:.8em;font-family:monospace;overflow-wrap:break-word
}

.snippet {
font-size:.8em;
}
.snippet code {
display: block;
font-size:1em;
font-family:monospace;overflow-wrap:break-word;
margin-top: 1em;
}

.tab-pane{
margin-top: 1.5em;
margin-left: 1em;
Expand Down Expand Up @@ -459,6 +469,10 @@
var tdImpact = $("<td><span class='" + violation["impact"] + "'>" + violation["impact"] + "</span></td>");
var tdRuleset = $("<td><span class='ruleset'>" + rulesetTagLabels[violation["applicableRulesetTag"]] + "</span></td>");
var tdLocation = $("<td><em>\"" + violation["fileTitle"] + "\"</em><br/><br/><code class='location'>" + violation["location"] + "</code></td>");
if (violation.html) {
var tdSnippet = $("<br/><br/><div class='snippet'>Snippet:<code>"+ violation.html.trim() + "</code></div>");
tdLocation.append(tdSnippet);
}
var tdRule = $("<td>" + violation["rule"] + "<br/><br/><span class='engine'>" + violation["engine"] + "</span></td>");

var desc = violation["desc"];
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1792,7 +1792,7 @@ es6-weak-map@^2.0.1:
es6-iterator "^2.0.1"
es6-symbol "^3.1.1"

escape-html@~1.0.3:
escape-html@^1.0.3, escape-html@~1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/escape-html/-/escape-html-1.0.3.tgz#0258eae4d3d0c0974de1c169188ef0051d1d1988"

Expand Down