Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bears/c_languages: Add OClintBear #2149

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .ci/deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
28 changes: 28 additions & 0 deletions tests/c_languages/OClintBearTest.py
Original file line number Diff line number Diff line change
@@ -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'})