Skip to content

Commit

Permalink
[analyzer] Teach scan-build to filter reports by file.
Browse files Browse the repository at this point in the history
That's a new GUI bell-and-whistle in the index.html page.
  • Loading branch information
briannafan authored and haoNoQ committed Feb 15, 2024
1 parent 6fce42f commit dcbb574
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
8 changes: 6 additions & 2 deletions clang/test/Analysis/scan-build/html_output.test
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,17 @@ CHECK-FILENAMES: report-{{.*}}.html
CHECK-FILENAMES: scanview.css
CHECK-FILENAMES: sorttable.js


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

// Let's confirm that the new filtering facility is present.
CHECK-INDEX-HTML: Filter Results by File

// The index should have a link to the report for the single issue.
CHECK-INDEX-HTML: <!-- REPORTBUG id="report-{{.*}}.html" -->


// The report should describe the issue.
RUN: cat %t.output_dir/*/report-*.html \
RUN: | FileCheck %s -check-prefix CHECK-REPORT-HTML
Expand Down
11 changes: 10 additions & 1 deletion clang/tools/scan-build/bin/scan-build
Original file line number Diff line number Diff line change
Expand Up @@ -722,9 +722,18 @@ ENDTEXT

print OUT <<ENDTEXT;
</table>
<h2>Filter Results by File</h2>
<input
type="text"
id="file_input"
onkeyup="searchFiles()"
placeholder="Enter a path or filename"
title="Enter a path or filename">
<h2>Reports</h2>
<table class="sortable" style="table-layout:automatic">
<table id="reports_table" class="sortable" style="table-layout:automatic">
<thead><tr>
<td>Bug Group</td>
<td class="sorttable_sorted">Bug Type<span id="sorttable_sortfwdind">&nbsp;&#x25BE;</span></td>
Expand Down
20 changes: 20 additions & 0 deletions clang/tools/scan-build/share/scan-build/sorttable.js
Original file line number Diff line number Diff line change
Expand Up @@ -490,3 +490,23 @@ var forEach = function(object, block, context) {
resolve.forEach(object, block, context);
}
};

// filter results by filename
const searchFiles = () => {
const columns = [
{ name: 'Filename', index: 2, isFilter: true },
]
const filterColumns = columns.filter(c => c.isFilter).map(c => c.index)
const trs = document.querySelectorAll(`#reports_table tr:not(.header)`)
const filter = document.querySelector('#file_input').value
const regex = new RegExp(escape(filter), 'i')
const isFoundInTds = td => regex.test(td.innerHTML)
const isFound = childrenArr => childrenArr.some(isFoundInTds)
const setTrStyleDisplay = ({ style, children }) => {
style.display = isFound([
...filterColumns.map(c => children[c])
]) ? '' : 'none'
}

trs.forEach(setTrStyleDisplay)
}

0 comments on commit dcbb574

Please sign in to comment.