Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -766,9 +766,8 @@ def test_html_checker_url(self):
content = f.read()

self.assertTrue(re.search(
'<a href=".*>alpha.clone.CloneChecker', content))
self.assertFalse(re.search(
'<a href=".*>UNKNOWN CHECKER NAME', content))
'"checker-url": "https://.*alpha-clone-clonechecker', content))
self.assertTrue(re.search('"checker-url": ""', content))
self.assertTrue(re.search('UNKNOWN CHECKER NAME', content))

# Test whether documentation urls are set properly for known
Expand All @@ -785,4 +784,4 @@ def test_html_checker_url(self):
with open(report_html, 'r',
encoding="utf-8", errors="ignore") as f:
content = f.read()
self.assertTrue(re.search('"url": null', content))
self.assertTrue(re.search('"url": ""', content))
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def to_macro_expansions(
'reportHash': report.report_hash,
'checker': {
'name': report.checker_name,
'url': self._get_doc_url(report)
'url': self._get_doc_url(report) or ''
},
'analyzerName': report.analyzer_name,
'line': report.line,
Expand Down Expand Up @@ -302,82 +302,22 @@ def create_index_html(self, output_dir: str):
for report in reports:
html_report_links.append({'link': html_file, 'report': report})

html_report_links.sort(
key=lambda data: self.files[data['report']['fileId']]['filePath'])

with io.StringIO() as table_reports:
# Create table header.
table_reports.write('''
<tr>
<th id="report-id">&nbsp;</th>
<th id="file-path">File</th>
<th id="severity">Severity</th>
<th id="checker-name">Checker name</th>
<th id="message">Message</th>
<th id="bug-path-length">Bug path length</th>
<th id="review-status">Review status</th>
</tr>''')

# Create table lines.
for i, data in enumerate(html_report_links):
html_file = os.path.basename(data['link'])
report = data['report']

severity = report['severity'].lower() \
if 'severity' in report \
and report['severity'] is not None \
else ''

review_status = report['reviewStatus'] \
if 'reviewStatus' in report and \
report['reviewStatus'] is not None \
else ''

events = report['events']
if events:
line = events[-1]['line']
message = events[-1]['message']
bug_path_length = len(events)
else:
line = report['line']
message = report['message']
bug_path_length = 1

rs = review_status.lower().replace(' ', '-')
file_path = self.files[report['fileId']]['filePath']

checker = report['checker']
doc_url = checker.get('url')
if doc_url:
checker_name_col_content = f'<a href="{doc_url}" '\
f'target="_blank">{checker["name"]}</a>'
else:
checker_name_col_content = checker["name"]

table_reports.write(f'''
<tr>
<td>{i + 1}</td>
<td file="{file_path}" line="{line}">
<a href="{html_file}#reportHash={report['reportHash']}">
{file_path} @ Line&nbsp;{line}
</a>
</td>
<td class="severity" severity="{severity}">
<i class="severity-{severity}"
title="{severity}"></i>
</td>
<td>{checker_name_col_content}</td>
<td>{message}</td>
<td class="bug-path-length">{bug_path_length}</td>
<td class="review-status review-status-{rs}">
{review_status}
</td>
</tr>''')

substitute_data = self._tag_contents
substitute_data.update({'table_reports': table_reports.getvalue()})

content = self._index.substitute(substitute_data)
table_reports = map(lambda data: {
'link': data['link'],
'file-path': data['report']['fileId'],
'report-hash': data['report']['reportHash'],
'checker-name': data['report']['checker']['name'],
'checker-url': data['report']['checker']['url'],
'line': data['report']['line'],
'message': data['report']['message'],
'review-status': data['report']['reviewStatus'],
'severity': data['report']['severity'],
'bug-path-length': len(data['report']['events'])
Comment on lines +309 to +315
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the props of data['report'] validating not necessary anymore?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The self._get_html_reports() that generates these reports ensures that these members can't be None.

}, html_report_links)

self._tag_contents['table_reports'] = json.dumps(list(table_reports))

content = self._index.substitute(self._tag_contents)
output_path = os.path.join(output_dir, 'index.html')
with open(output_path, 'w+', encoding='utf-8',
errors='replace') as html_output:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#report-list {
#report-list-table {
width: 100%;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,45 @@
${browser_support}
${bug_list}

var reports = ${table_reports};

window.onload = function () {
if (!browserCompatible) {
setNonCompatibleBrowserMessage();
} else {
BugList.init()
BugList.initByUrl();
}
}
</script>
</head>
<body>
<div class="container">
<a href="statistics.html" class="button">Go To Statistics</a>
<table id="report-list">
${table_reports}
<table id="report-list-table">
<thead>
<tr>
<th id="report-id">&nbsp;</th>
<th id="file-path">File</th>
<th id="severity">Severity</th>
<th id="checker-name">Checker name</th>
<th id="message">Message</th>
<th id="bug-path-length">Bug path length</th>
<th id="review-status">Review status</th>
</tr>
</thead>
<tbody id="report-list">
</tbody>
</table>

<select id="page-size" onchange="BugList.initByUrl()">
<option value="25">25</option>
<option value="50">50</option>
<option value="100">100</option>
</select>

<button onclick="BugList.prevPage()">&lt;</button>
<select id="page-number" onchange="BugList.selectPage(this.value)"></select>
<button onclick="BugList.nextPage()">&gt;</button>
</div>
</body>
</html>
Loading