forked from NREL/OpenStudio
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[chore] add a workflow for cppcheck and fix all cppcheck issues
Suppress a few errors [chore] Pass std::string by const-ref: deal with the case where it's the first argument only ``` exts = [".hpp", "_Impl.hpp", ".cpp"] found_diffs = {} for file in files: found_diffs[file] = {} for ext in exts: try: with open(f"../{file}{ext}", 'r') as f: content = f.read() except FileNotFoundError: continue lines = content.splitlines() new_lines = [] has_diff = False for line in lines: if '(std::string ' in line: if not ext in found_diffs[file]: found_diffs[file][ext] = 1 else: found_diffs[file][ext] += 1 print(f"{file}{ext}, {line}") has_diff = True new_lines.append(line.replace('std::string', 'const std::string&')) else: new_lines.append(line) if has_diff: with open(f"../{file}{ext}", 'w') as f: f.write("\n".join(new_lines) + "\n") ``` Manually fix the rest of `passedByValue`cppcheck Correct a funcArgNamesDifferent and a typo in arg in Curves in french, independant... not independent like in enligsh, so pardon my french! Fix the funcArgNamesDifferent ScheduleTypeLimits: cannot pass const std::string& since string is mutated. Fix a lot more warnings, mostly missingOverride Fix a invalidPrintfArgType_sint warning by using fmt instead of sprintf (faster anyways) Fix a few more add a few more global suppressions False positives for Intersection: `[src/utilities/geometry/Intersection.cpp:158]:(warning),[constStatement],Found suspicious operator '>'` Fix a few more things Fix 60 cppcheck warnings in RoofGeometry_Details.hpp Fix isomodel noConstructor Fix last warnings in isomodel delete the copy/assignment operators for OutFiles instread of runtime error suppress something that was never implemented TODO: review please : Ignore a warning about RubyInterpreter::evalString that could be static Fix a few more warnings in ThreeJS cppcheck seems to be chocking on the gtest macros for these core tests, so ignore Not sure if it's really a problem, please double check `Using iterator to local container 'ws' that may be invalid.` I'm specifically excluding the nano folder from cppcheck (`-i src/nano`) yet cppcheck still reports a warning, so excluding it Ignore some false warnings about const Fix more More, almost there! Minor changes A bit more, almooooost Almost final tweaks, I have functional changes to Date::Date(std::string) to make clang-format touched files Update gitignore Suppress last one Tweak cppcheck: print progress to screen, and output problems to the file. 3>&1 1>&2 2>&3 is how you swap stderr and stdout, because tee can only accept stdout.
- Loading branch information
Showing
331 changed files
with
1,594 additions
and
1,405 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,3 +15,5 @@ developer/msvc/Visualizers/all_concat.natvis | |
*.sublime-projet | ||
*.cache | ||
.clangd/ | ||
cppcheck.txt* | ||
clang_format.patch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
import re | ||
from collections import Counter | ||
|
||
|
||
def colorize(lines): | ||
def bold(s): | ||
return '\x1b[1m{}\x1b[0m'.format(s) | ||
|
||
def red(s): | ||
return '\x1b[31m{}\x1b[0m'.format(s) | ||
|
||
def green(s): | ||
return '\x1b[32m{}\x1b[0m'.format(s) | ||
|
||
def yellow(s): | ||
return '\x1b[33m{}\x1b[0m'.format(s) | ||
|
||
def blue(s): | ||
return '\x1b[34m{}\x1b[0m'.format(s) | ||
|
||
def magenta(s): # purple | ||
return '\x1b[35m{}\x1b[0m'.format(s) | ||
|
||
def cyan(s): | ||
return '\x1b[36m{}\x1b[0m'.format(s) | ||
|
||
def format_severity(txt, severity): | ||
""" | ||
http://cppcheck.sourceforge.net/devinfo/doxyoutput/classSeverity.html | ||
enum: | ||
none, error, warning, style, performance, | ||
portability, information, debug | ||
""" | ||
if severity == "none": | ||
return txt | ||
if severity == "error": | ||
return red(txt) | ||
if severity == "warning": | ||
return yellow(txt) | ||
if severity == 'style': | ||
return blue(txt) | ||
if severity == "performance": | ||
return cyan(txt) | ||
if severity == "portability": | ||
return magenta(txt) | ||
if severity == "information": | ||
return green(txt) | ||
if severity == "debug": | ||
return txt | ||
|
||
return txt | ||
|
||
re_message = re.compile(r'\[(?P<file>.*):(?P<line>.*?)\]:' | ||
r'\((?P<severity>.*?)\),\[(?P<id>.*?)\],' | ||
r'(?P<message>.*)') | ||
|
||
colored_lines = [] | ||
matched_messages = [] | ||
|
||
colored_lines = [] | ||
matched_messages = [] | ||
|
||
for line in lines: | ||
m = re_message.match(line) | ||
if m: | ||
d = m.groupdict() | ||
matched_messages.append(d) | ||
else: | ||
colored_lines.append(red(line)) | ||
|
||
severity_order = ['error', 'warning', 'performance', 'portability', | ||
'style', 'information', 'debug', 'none'] | ||
|
||
counter = Counter(d['severity'] for d in matched_messages) | ||
summary_line = "\n\n==========================================\n" | ||
summary_line += " {}:\n".format(bold(red("CPPCHECK Summary"))) | ||
summary_line += "------------------------------------------" | ||
|
||
for severity in severity_order: | ||
n_severity = counter[severity] | ||
summary_line += "\n * " | ||
if n_severity: | ||
summary_line += format_severity(n_severity, severity) | ||
else: | ||
# summary_line += green("No {}(s)".format(severity)) | ||
summary_line += green("No") | ||
summary_line += " {}(s)".format(format_severity(severity, severity)) | ||
|
||
summary_line += "\n==========================================\n\n" | ||
|
||
n_errors = counter['error'] | ||
# if n_errors: | ||
# summary_line += red("{} Errors".format(n_errors)) | ||
# else: | ||
# summary_line = green("No Errors") | ||
|
||
n_warnings = counter['warning'] | ||
# if n_warnings: | ||
# summary_line += yellow("{} Warnings".format(n_warnings)) | ||
# else: | ||
# summary_line = green("No Warnings") | ||
|
||
n_styles = counter['style'] | ||
n_performances = counter['performance'] | ||
n_portabilities = counter['portability'] | ||
# n_informations = counter['information'] | ||
|
||
# n_debugs = counter['debug'] | ||
|
||
# Start by sorting by filename | ||
matched_messages.sort(key=lambda d: d['file']) | ||
matched_messages.sort(key=lambda d: severity_order.index(d['severity'])) | ||
|
||
# Now sort by the severity we cared about | ||
for d in matched_messages: | ||
|
||
f = d['file'] | ||
line = d['line'] | ||
severity = d['severity'] | ||
iid = d['id'] | ||
message = d['message'] | ||
|
||
colored_lines.append( | ||
"[{f}:{line}]:({severity}),[{i}],{message}" | ||
.format(f=magenta(f), # format_severity(f, severity), | ||
line=green(line), | ||
severity=format_severity(severity, severity), | ||
i=bold(iid), | ||
message=message)) | ||
|
||
return (colored_lines, summary_line, n_errors, n_warnings, | ||
n_performances, n_portabilities, n_styles) | ||
|
||
|
||
if __name__ == '__main__': | ||
with open('cppcheck.txt', 'r') as f: | ||
content = f.read() | ||
|
||
lines = content.splitlines() | ||
(colored_lines, summary_line, n_errors, n_warnings, | ||
n_performances, n_portabilities, n_styles) = colorize(lines) | ||
print(summary_line) | ||
# sys.stdout.writelines(colored_lines) | ||
print("\n".join(colored_lines)) | ||
n_tot = (n_errors + n_warnings + n_performances | ||
+ n_portabilities + n_styles) | ||
if n_tot > 0: | ||
exit(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.