Skip to content

Commit dcbb574

Browse files
briannafanhaoNoQ
authored andcommitted
[analyzer] Teach scan-build to filter reports by file.
That's a new GUI bell-and-whistle in the index.html page.
1 parent 6fce42f commit dcbb574

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

clang/test/Analysis/scan-build/html_output.test

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,17 @@ CHECK-FILENAMES: report-{{.*}}.html
1919
CHECK-FILENAMES: scanview.css
2020
CHECK-FILENAMES: sorttable.js
2121

22-
23-
// The index should have a link to the report for the single issue.
22+
// Tests for the front page.
2423
RUN: cat %t.output_dir/*/index.html \
2524
RUN: | FileCheck %s -check-prefix CHECK-INDEX-HTML
2625

26+
// Let's confirm that the new filtering facility is present.
27+
CHECK-INDEX-HTML: Filter Results by File
28+
29+
// The index should have a link to the report for the single issue.
2730
CHECK-INDEX-HTML: <!-- REPORTBUG id="report-{{.*}}.html" -->
2831

32+
2933
// The report should describe the issue.
3034
RUN: cat %t.output_dir/*/report-*.html \
3135
RUN: | FileCheck %s -check-prefix CHECK-REPORT-HTML

clang/tools/scan-build/bin/scan-build

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,9 +722,18 @@ ENDTEXT
722722

723723
print OUT <<ENDTEXT;
724724
</table>
725+
726+
<h2>Filter Results by File</h2>
727+
<input
728+
type="text"
729+
id="file_input"
730+
onkeyup="searchFiles()"
731+
placeholder="Enter a path or filename"
732+
title="Enter a path or filename">
733+
725734
<h2>Reports</h2>
726735
727-
<table class="sortable" style="table-layout:automatic">
736+
<table id="reports_table" class="sortable" style="table-layout:automatic">
728737
<thead><tr>
729738
<td>Bug Group</td>
730739
<td class="sorttable_sorted">Bug Type<span id="sorttable_sortfwdind">&nbsp;&#x25BE;</span></td>

clang/tools/scan-build/share/scan-build/sorttable.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,3 +490,23 @@ var forEach = function(object, block, context) {
490490
resolve.forEach(object, block, context);
491491
}
492492
};
493+
494+
// filter results by filename
495+
const searchFiles = () => {
496+
const columns = [
497+
{ name: 'Filename', index: 2, isFilter: true },
498+
]
499+
const filterColumns = columns.filter(c => c.isFilter).map(c => c.index)
500+
const trs = document.querySelectorAll(`#reports_table tr:not(.header)`)
501+
const filter = document.querySelector('#file_input').value
502+
const regex = new RegExp(escape(filter), 'i')
503+
const isFoundInTds = td => regex.test(td.innerHTML)
504+
const isFound = childrenArr => childrenArr.some(isFoundInTds)
505+
const setTrStyleDisplay = ({ style, children }) => {
506+
style.display = isFound([
507+
...filterColumns.map(c => children[c])
508+
]) ? '' : 'none'
509+
}
510+
511+
trs.forEach(setTrStyleDisplay)
512+
}

0 commit comments

Comments
 (0)