Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OCLint rule customization

I am using OCLint static code analysis tool for objective-C and want to find out how to customize rules? The rules are represented by set of dylib files.

like image 957
leon4ic Avatar asked Jan 16 '13 12:01

leon4ic


3 Answers

In lieu of passing configuration as arguments (see Jon Boydell's answer), you can also create a YML file named .oclint in the project directory.

Here's an example file that customizes a few things:

rules:
  - LongLine
disable-rules:
rulePaths:
  - /etc/rules
rule-configurations:
 - key: LONG_LINE
   value: 20
output: filename
report-type: xml
max-priority-1: 10
max-priority-2: 20
max-priority-3: 30
enable-clang-static-analyzer: false
like image 105
nschum Avatar answered Nov 20 '22 16:11

nschum


The answer, as with so many things, is that it depends.

  1. If you want to write your own custom rule then you'll need to get down and dirty into writing your own rule, in C++ on top of the existing source code. Check out the oclint-rules/rules directory, size/LongLineRule.cpp is a simple rule to get going with. You'll need to recompile, etc.

  2. If you want to change the parameters of an existing rule you need to add the command line parameter -rc=<rulename>=<value> to the call to oclint. For example, if you want the long lines rule to only activate for lines longer than 150 chars you need to add -rc=LONG_LINE=150.

I don't have the patience to list out all the different parameters you can change. The list of rules is here http://docs.oclint.org/en/dev/rules/index.html and a list of threshold based rules here http://docs.oclint.org/en/dev/customizing/rules.html but there's no list of acceptable values and I don't know whether these two URLs cover all the rules or not. You might have to look into the source code for each rule to work out how it works.

like image 35
Jon Boydell Avatar answered Nov 20 '22 14:11

Jon Boydell


If you're using Xcode script you should use oclint_args like this:

oclint-json-compilation-database oclint_args "-rc LONG_LINE=150" | sed 's/(..\m{1,2}:[0-9]:[0-9]*:)/\1 warning:/'

in that sample I'm changing the rule of LONG_LINE to 150 chars

like image 41
CEGONYA Avatar answered Nov 20 '22 14:11

CEGONYA