diff --git a/.ci/deps.sh b/.ci/deps.sh index d3b544702b..8618e5b5ee 100644 --- a/.ci/deps.sh +++ b/.ci/deps.sh @@ -61,3 +61,10 @@ wget "https://downloads.sourceforge.net/project/astyle/astyle/astyle%203.0.1/ast tar -xvzf ~/astyle.tar.gz -C ~/ make -C ~/astyle/build/gcc sudo make install -C ~/astyle/build/gcc + +# oclint installation +if [ ! -e ~/oclint-0.13/bin/oclint ]; then +wget "https://github.com/oclint/oclint/releases/download/v0.13/oclint-0.13-x86_64-linux-4.4.0-93-generic.tar.gz" +tar -xvzf oclint-0.13-x86_64-linux-4.4.0-93-generic.tar.gz -C ~/ +sudo chmod +x ~/oclint-0.13/bin/oclint +fi diff --git a/bears/c_languages/OClintBear.py b/bears/c_languages/OClintBear.py new file mode 100644 index 0000000000..fd4a3965c0 --- /dev/null +++ b/bears/c_languages/OClintBear.py @@ -0,0 +1,33 @@ +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'} + AUTHORS = {'The coala developers'} + AUTHORS_EMAILS = {'coala-devel@googlegroups.com'} + LICENSE = 'AGPL-3.0' + + @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/circle.yml b/circle.yml index 23d37a01e9..b87027a45b 100644 --- a/circle.yml +++ b/circle.yml @@ -34,6 +34,7 @@ dependencies: - echo 'export PATH=$PATH:~/elm-format-0.18' >> ~/.circlerc - echo 'export PATH=$PATH:~/phpmd' >> ~/.circlerc - echo 'export R_LIB_USER=~/.RLibrary' >> ~/.circlerc + - echo 'export PATH=$PATH:~/oclint-0.13/bin' >> ~/.circlerc - sed -i '/source \/home\/ubuntu\/virtualenvs\//d' ~/.circlerc - mkdir -p ~/.RLibrary - nvm alias default node diff --git a/tests/c_languages/OClintBearTest.py b/tests/c_languages/OClintBearTest.py new file mode 100644 index 0000000000..551491a090 --- /dev/null +++ b/tests/c_languages/OClintBearTest.py @@ -0,0 +1,28 @@ +from bears.c_languages.OClintBear import OClintBear +from coalib.testing.LocalBearTestHelper import verify_local_bear + +bad_file = """ +int main() { + int i = 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=(good_file, bad_file), + invalid_files=(), + settings={'oclint_cli_options': '-max-priority-3=4'})