forked from coala/coala-bears
-
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.
References coala#389
- Loading branch information
Showing
3 changed files
with
76 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from coalib.bearlib.abstractions.Linter import linter | ||
from coalib.results.RESULT_SEVERITY import RESULT_SEVERITY | ||
from coalib.settings.Setting import typed_list | ||
|
||
|
||
@linter(executable="cppcheck", | ||
use_stdout=False, | ||
use_stderr=True, | ||
output_format="regex", | ||
output_regex=r'(?P<line>\d+):(?P<severity>[a-zA-Z]+):' | ||
r'(?P<origin>[a-zA-Z]+):(?P<message>.*)', | ||
severity_map={"error": RESULT_SEVERITY.MAJOR, | ||
"warning": RESULT_SEVERITY.NORMAL, | ||
"style": RESULT_SEVERITY.INFO}) | ||
class CPPCheckBear: | ||
""" | ||
Report possible security weaknesses for C/C++. | ||
For more information, consult <https://github.com/danmar/cppcheck>. | ||
""" | ||
|
||
LANGUAGES = "C", "C++" | ||
|
||
@staticmethod | ||
def create_arguments(filename, file, config_file, | ||
enable: typed_list(str)=[]): | ||
""" | ||
:param enable: | ||
Choose specific issues to report. Issues that can be | ||
reported are: all, warning, style, performance, | ||
portability, information, unusedFunction, | ||
missingInclude | ||
""" | ||
args = ("--template={line}:{severity}:{id}:{message}",) | ||
|
||
if enable: | ||
args += ('--enable=' + ",".join(enable),) | ||
|
||
return args + (filename,) |
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,37 @@ | ||
from bears.c_languages.CPPCheckBear import CPPCheckBear | ||
from tests.LocalBearTestHelper import verify_local_bear | ||
|
||
good_file = """ | ||
using namespace std; | ||
int main() { | ||
cout << "Hello, world!" << endl; | ||
return 0; | ||
}""".splitlines(keepends=True) | ||
|
||
warn_file = """ | ||
void f1(struct fred_t *p) | ||
{ | ||
int x; | ||
if (p) | ||
do_something(x); | ||
}""".splitlines(keepends=True) | ||
|
||
bad_file = """ | ||
#define f(c) { \ | ||
char *p = new char[10]; \ | ||
p[c] = 42; \ | ||
} | ||
int main() { | ||
f(100); | ||
return 0; | ||
}""".splitlines(keepends=True) | ||
|
||
|
||
CPPCheckBearTest1 = verify_local_bear(CPPCheckBear, | ||
valid_files=(good_file, warn_file), | ||
invalid_files=(bad_file,)) | ||
|
||
CPPCheckBearTest2 = verify_local_bear(CPPCheckBear, | ||
valid_files=(good_file,), | ||
invalid_files=(warn_file, bad_file), | ||
settings={'enable': 'unusedFunction'}) |