Skip to content

Commit

Permalink
bears/c_languages: Add OClintBear
Browse files Browse the repository at this point in the history
Adds `OClintBear` that provides static code analysis for C, C++ and
Objective-C.

Closes coala#1953
  • Loading branch information
idealrealism committed Dec 6, 2017
1 parent 1a7c514 commit a0330b9
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .ci/deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,11 @@ 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
mkdir -p ~/oclint-0.13
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 ~/oclint-0.13
sudo chmod +x ~/oclint-0.13/bin/oclint
fi
33 changes: 33 additions & 0 deletions bears/c_languages/OClintBear.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import shlex

from coalib.bearlib.abstractions.Linter import linter


@linter(executable='oclint',
output_format='regex',
output_regex=r'.+:(?P<line>\d+):(?P<column>\d+): (?P<message>.*)')
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 <http://oclint.org/>.
"""

LANGUAGES = {'C', 'C++', 'Objective-C'}
CAN_DETECT = {'Formatting', 'Duplication', 'Syntax', 'Complexity', 'Smell',
'Redundancy', 'Unreachable Code'}
AUTHORS = {'The coala developers'}
AUTHORS_EMAILS = {'[email protected]'}
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,)
1 change: 1 addition & 0 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 36 additions & 0 deletions tests/c_languages/OClintBearTest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
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=(good_file,),
invalid_files=(),
settings={'oclint_cli_options': '-max-priority-1=2'})

0 comments on commit a0330b9

Please sign in to comment.