diff --git a/bears/c_languages/OClintBear.py b/bears/c_languages/OClintBear.py new file mode 100644 index 0000000000..9662668fb0 --- /dev/null +++ b/bears/c_languages/OClintBear.py @@ -0,0 +1,31 @@ +import shlex + +from coalib.bearlib.abstractions.Linter import linter + + +@linter(executable='oclint', + output_format='regex', + output_regex=r'.+:(?P\d+):(?P\d+): (?P.*)') +class OClintBear: + """ + OCLint is a static code analysis tool for improving quality and + reducing defects by inspecting C, C++ and Objective-C code. + + For more information, consult . + """ + + LANGUAGES = {'C', 'C++', 'Objective-C'} + CAN_DETECT = {'Formatting', 'Duplication', 'Syntax', 'Complexity', 'Smell', + 'Redundancy', 'Unreachable Code'} + + @staticmethod + def create_arguments(filename, file, config_file, + oclint_cli_options: str=''): + + """ + :param oclint_cli_options: Any other flags you wish to pass to oclint. + """ + args = () + if oclint_cli_options: + args += tuple(shlex.split(oclint_cli_options)) + return args + (filename,) diff --git a/tests/c_languages/OClintBearTest.py b/tests/c_languages/OClintBearTest.py new file mode 100644 index 0000000000..b03327cf3c --- /dev/null +++ b/tests/c_languages/OClintBearTest.py @@ -0,0 +1,37 @@ +from bears.c_languages.OClintBear import OClintBear +from coalib.testing.LocalBearTestHelper import verify_local_bear + +bad_file = """ +int main() { + int i = 0, j = 1; + if (j) { + if (i) { + return 1; + j = 0; + } + } + return 0; +} +""" + + +good_file = """ +using namespace std; +int main() { + cout << "Hello, world!" << endl; + return 0; +} +""" + + +OClintBearTest = verify_local_bear(OClintBear, + valid_files=(good_file,), + invalid_files=(bad_file,)) + + +OClintBearWithSettingsTest = verify_local_bear( + OClintBear, + valid_files=(bad_file, good_file), + invalid_files=(), + settings={'oclint_cli_options': '-max-priority-1=2'}) +