From ab75b047b0488eba83d7260f289ea8c0e696b672 Mon Sep 17 00:00:00 2001 From: Boris Egorov Date: Fri, 11 Mar 2016 10:55:35 +0600 Subject: [PATCH 1/3] htmlreport: Do not recalculate stat counters --- htmlreport/cppcheck-htmlreport | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/htmlreport/cppcheck-htmlreport b/htmlreport/cppcheck-htmlreport index bd1d2f47e..1db5c70fd 100755 --- a/htmlreport/cppcheck-htmlreport +++ b/htmlreport/cppcheck-htmlreport @@ -532,22 +532,24 @@ if __name__ == '__main__': stats.append(error['id']) # get the stats stats_count += 1 + counter = Counter(stats) + stat_html = [] # the following lines sort the stat primary by value (occurrences), # but if two IDs occur equally often, then we sort them alphabetically by warning ID try: - cnt_max = Counter(stats).most_common()[0][1] + cnt_max = counter.most_common()[0][1] except IndexError: cnt_max = 0 try: - cnt_min = Counter(stats).most_common()[-1][1] + cnt_min = counter.most_common()[-1][1] except IndexError: cnt_min = 0 for occurrences in reversed(range(cnt_min, cnt_max + 1)): - for _id in [k for k, v in sorted(Counter(stats).items()) if v == occurrences]: - stat_html.append(" " + str(dict(Counter(stats).most_common())[_id]) + " " + str(_id) + "
\n") + for _id in [k for k, v in sorted(counter.items()) if v == occurrences]: + stat_html.append(" " + str(dict(counter.most_common())[_id]) + " " + str(_id) + "
\n") output_file.write(HTML_HEAD.replace('id="menu" dir="rtl"', 'id="menu_index"', 1).replace("Defects:", "Defect summary;", 1) % (options.title, '', options.title, '', '')) output_file.write('

\n' + ' ' + str(stats_count) + ' total

\n' + ''.join(stat_html) + '

Statistics

') From e4f81ba755fcb65ac9d8f94c33f47f0e88bb0d43 Mon Sep 17 00:00:00 2001 From: Boris Egorov Date: Fri, 11 Mar 2016 11:12:52 +0600 Subject: [PATCH 2/3] htmlreport: Few style fixes * Fix wrong indentation * Use single quotes for consistency * It is fine to substitute %s with empty str --- htmlreport/cppcheck-htmlreport | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/htmlreport/cppcheck-htmlreport b/htmlreport/cppcheck-htmlreport index 1db5c70fd..20f848dad 100755 --- a/htmlreport/cppcheck-htmlreport +++ b/htmlreport/cppcheck-htmlreport @@ -590,27 +590,20 @@ if __name__ == '__main__': if error['severity'] == 'error': error_class = 'class="error"' if error['id'] == 'missingInclude': - output_file.write( - '\n %s%s%s' % - (error['id'], error['severity'], error['msg'])) + output_file.write( + '\n %s%s%s' % + (error['id'], error['severity'], error['msg'])) elif (error['id'] == 'unmatchedSuppression') and filename.endswith('*'): output_file.write( - "\n %s%s%s" % + '\n %s%s%s' % (error['id'], error['severity'], error_class, error['msg'])) else: - if cwe_url: - output_file.write( - "\n %d%s%s%s%s" % - (data['htmlfile'], error['line'], error['line'], - error['id'], cwe_url, error['severity'], error_class, - error['msg'])) - else: - output_file.write( - "\n %d%s%s%s" % - (data['htmlfile'], error['line'], error['line'], - error['id'], error['severity'], error_class, - error['msg'])) + output_file.write( + '\n %d%s%s%s%s' % + (data['htmlfile'], error['line'], error['line'], + error['id'], cwe_url, error['severity'], error_class, + error['msg'])) output_file.write('\n ') output_file.write(HTML_FOOTER % contentHandler.versionCppcheck) From cbb4b1bb2214b2b59bb9f28a727fe39f3ee6f176 Mon Sep 17 00:00:00 2001 From: Boris Egorov Date: Fri, 11 Mar 2016 11:20:44 +0600 Subject: [PATCH 3/3] htmlreport: Add checkboxes to toggle error visibility by id --- htmlreport/cppcheck-htmlreport | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/htmlreport/cppcheck-htmlreport b/htmlreport/cppcheck-htmlreport index 20f848dad..a5434d96f 100755 --- a/htmlreport/cppcheck-htmlreport +++ b/htmlreport/cppcheck-htmlreport @@ -215,6 +215,17 @@ HTML_HEAD = """ clickable.onclick = toggle; } } + function set_class_display(c, st) { + var elements = document.querySelectorAll('.' + c), + len = elements.length; + for (i = 0; i < len; i++) { + elements[i].style.display = st; + } + } + function toggle_class_visibility(id) { + var box = document.getElementById(id); + set_class_display(id, box.checked ? '' : 'none'); + } @@ -547,12 +558,18 @@ if __name__ == '__main__': except IndexError: cnt_min = 0 + stat_fmt = " {}{}" for occurrences in reversed(range(cnt_min, cnt_max + 1)): for _id in [k for k, v in sorted(counter.items()) if v == occurrences]: - stat_html.append(" " + str(dict(counter.most_common())[_id]) + " " + str(_id) + "
\n") + stat_html.append(stat_fmt.format(_id, _id, dict(counter.most_common())[_id], _id)) output_file.write(HTML_HEAD.replace('id="menu" dir="rtl"', 'id="menu_index"', 1).replace("Defects:", "Defect summary;", 1) % (options.title, '', options.title, '', '')) - output_file.write('

\n' + ' ' + str(stats_count) + ' total

\n' + ''.join(stat_html) + '

Statistics

') + output_file.write(' ') + output_file.write(' ') + output_file.write(''.join(stat_html)) + output_file.write(' ') + output_file.write('
Show#Defect ID
' + str(stats_count) + 'total
') + output_file.write(' Statistics

') output_file.write(HTML_HEAD_END.replace("content", "content_index", 1)) output_file.write(' \n') @@ -591,17 +608,17 @@ if __name__ == '__main__': error_class = 'class="error"' if error['id'] == 'missingInclude': output_file.write( - '\n ' % - (error['id'], error['severity'], error['msg'])) + '\n ' % + (error['id'], error['id'], error['severity'], error['msg'])) elif (error['id'] == 'unmatchedSuppression') and filename.endswith('*'): output_file.write( - '\n ' % - (error['id'], error['severity'], error_class, + '\n ' % + (error['id'], error['id'], error['severity'], error_class, error['msg'])) else: output_file.write( - '\n ' % - (data['htmlfile'], error['line'], error['line'], + '\n ' % + (error['id'], data['htmlfile'], error['line'], error['line'], error['id'], cwe_url, error['severity'], error_class, error['msg']))
%s%s%s
%s%s%s
%s%s%s
%s%s%s
%d%s%s%s%s
%d%s%s%s%s