Skip to content

Commit 027dc2b

Browse files
This fixes the html template when using '-fmt=html'
- resolves HTML escaping issues within the template - resolves reference issues to reportInfo struct i.e. issues -> Issues, metrics -> Stats
1 parent f9b4187 commit 027dc2b

File tree

1 file changed

+27
-32
lines changed

1 file changed

+27
-32
lines changed

output/template.go

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ const html = `
6262
level = "is-warning";
6363
}
6464
return (
65-
<div className={ "tag " + level }>
65+
<div className="tag { level }">
6666
{ this.props.label }: { this.props.level }
6767
</div>
6868
);
@@ -100,24 +100,24 @@ const html = `
100100
render: function() {
101101
return (
102102
<p className="help">
103-
Scanned { this.props.data.metrics.files.toLocaleString() } files
104-
with { this.props.data.metrics.lines.toLocaleString() } lines of code.
103+
Scanned { this.props.data.Stats.files.toLocaleString() } files
104+
with { this.props.data.Stats.lines.toLocaleString() } lines of code.
105105
</p>
106106
);
107107
}
108108
});
109109
110110
var Issues = React.createClass({
111111
render: function() {
112-
if (this.props.data.metrics.files === 0) {
112+
if (this.props.data.Stats.files === 0) {
113113
return (
114114
<div className="notification">
115115
No source files found. Do you even Go?
116116
</div>
117117
);
118118
}
119119
120-
if (this.props.data.issues.length === 0) {
120+
if (this.props.data.Issues.length === 0) {
121121
return (
122122
<div>
123123
<div className="notification">
@@ -128,7 +128,7 @@ const html = `
128128
);
129129
}
130130
131-
var issues = this.props.data.issues
131+
var issues = this.props.data.Issues
132132
.filter(function(issue) {
133133
return this.props.severity.includes(issue.severity);
134134
}.bind(this))
@@ -151,7 +151,7 @@ const html = `
151151
<div>
152152
<div className="notification">
153153
No issues matched given filters
154-
(of total { this.props.data.issues.length } issues).
154+
(of total { this.props.data.Issues.length } issues).
155155
</div>
156156
<Stats data={ this.props.data } />
157157
</div>
@@ -182,31 +182,32 @@ const html = `
182182
var highDisabled = !this.props.available.includes("HIGH");
183183
var mediumDisabled = !this.props.available.includes("MEDIUM");
184184
var lowDisabled = !this.props.available.includes("LOW");
185-
185+
var on = "", off = "disabled";
186+
var HIGH = "HIGH", MEDIUM = "MEDIUM", LOW = "LOW";
186187
return (
187188
<span>
188-
<label className={"label checkbox " + (highDisabled ? "disabled" : "") }>
189+
<label className="label checkbox { (highDisabled ? off : on )}">
189190
<input
190191
type="checkbox"
191-
checked={ this.props.selected.includes("HIGH") }
192+
checked={ this.props.selected.includes(HIGH) }
192193
disabled={ highDisabled }
193-
onChange={ this.handleChange("HIGH") }/>
194+
onChange={ this.handleChange(HIGH) }/>
194195
High
195196
</label>
196-
<label className={"label checkbox " + (mediumDisabled ? "disabled" : "") }>
197+
<label className="label checkbox {( mediumDisabled ? off : on )}">
197198
<input
198199
type="checkbox"
199-
checked={ this.props.selected.includes("MEDIUM") }
200+
checked={ this.props.selected.includes(MEDIUM) }
200201
disabled={ mediumDisabled }
201-
onChange={ this.handleChange("MEDIUM") }/>
202+
onChange={ this.handleChange(MEDIUM) }/>
202203
Medium
203204
</label>
204-
<label className={"label checkbox " + (lowDisabled ? "disabled" : "") }>
205+
<label className="label checkbox {( lowDisabled ? off : on )}">
205206
<input
206207
type="checkbox"
207-
checked={ this.props.selected.includes("LOW") }
208+
checked={ this.props.selected.includes(LOW) }
208209
disabled={ lowDisabled }
209-
onChange={ this.handleChange("LOW") }/>
210+
onChange={ this.handleChange(LOW) }/>
210211
Low
211212
</label>
212213
</span>
@@ -231,13 +232,13 @@ const html = `
231232
render: function() {
232233
var issueTypes = this.props.allIssueTypes
233234
.map(function(it) {
235+
var matches = this.props.issueType == it
234236
return (
235-
<option value={ it } selected={ this.props.issueType == it }>
237+
<option value={ it } selected={ matches }>
236238
{ it }
237239
</option>
238240
);
239241
}.bind(this));
240-
241242
return (
242243
<nav className="panel">
243244
<div className="panel-heading">
@@ -282,7 +283,6 @@ const html = `
282283
);
283284
}
284285
});
285-
286286
var IssueBrowser = React.createClass({
287287
getInitialState: function() {
288288
return {};
@@ -291,11 +291,11 @@ const html = `
291291
this.updateIssues(this.props.data);
292292
},
293293
handleSeverity: function(val) {
294-
this.updateIssueTypes(this.props.data.issues, val, this.state.confidence);
294+
this.updateIssueTypes(this.props.data.Issues, val, this.state.confidence);
295295
this.setState({severity: val});
296296
},
297297
handleConfidence: function(val) {
298-
this.updateIssueTypes(this.props.data.issues, this.state.severity, val);
298+
this.updateIssueTypes(this.props.data.Issues, this.state.severity, val);
299299
this.setState({confidence: val});
300300
},
301301
handleIssueType: function(val) {
@@ -306,30 +306,25 @@ const html = `
306306
this.setState({data: data});
307307
return;
308308
}
309-
310-
var allSeverities = data.issues
309+
var allSeverities = data.Issues
311310
.map(function(issue) {
312311
return issue.severity
313312
})
314313
.sort()
315314
.filter(function(item, pos, ary) {
316315
return !pos || item != ary[pos - 1];
317316
});
318-
319-
var allConfidences = data.issues
317+
var allConfidences = data.Issues
320318
.map(function(issue) {
321319
return issue.confidence
322320
})
323321
.sort()
324322
.filter(function(item, pos, ary) {
325323
return !pos || item != ary[pos - 1];
326324
});
327-
328325
var selectedSeverities = allSeverities;
329326
var selectedConfidences = allConfidences;
330-
331-
this.updateIssueTypes(data.issues, selectedSeverities, selectedConfidences);
332-
327+
this.updateIssueTypes(data.Issues, selectedSeverities, selectedConfidences);
333328
this.setState({
334329
data: data,
335330
severity: selectedSeverities,
@@ -358,7 +353,7 @@ const html = `
358353
if (this.state.issueType && !allTypes.includes(this.state.issueType)) {
359354
this.setState({issueType: null});
360355
}
361-
356+
362357
this.setState({allIssueTypes: allTypes});
363358
},
364359
render: function() {
@@ -391,7 +386,7 @@ const html = `
391386
);
392387
}
393388
});
394-
389+
395390
ReactDOM.render(
396391
<IssueBrowser data={ data } />,
397392
document.getElementById("content")

0 commit comments

Comments
 (0)