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.
Adds `OClintBear` that provides static code analysis for C, C++ and Objective-C. Closes coala#1953
- Loading branch information
1 parent
1a7c514
commit a0330b9
Showing
4 changed files
with
78 additions
and
0 deletions.
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,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,) |
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,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'}) |