Configure OCLint Rule

I am using OCLint static code analysis tool for objective-C and want to know how to configure the rules? Rules are represented by a set of dylib files.

+6
source share
3 answers

The answer, as in many things, is that it depends.

  • If you want to write your own custom rule, you will need to go down and mess up your own custom rule in C ++ on top of the existing source code. Check the oclint-rules/rules directory, size/LongLineRule.cpp - this is a simple rule to work with. You will need to recompile, etc.

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

I do not have the patience to list all the various parameters that you can change. The list of rules is here http://docs.oclint.org/en/dev/rules/index.html and the list of rules based on thresholds is here http://docs.oclint.org/en/dev/customizing/rules.html but thereโ€™s no list of valid values, and I donโ€™t know if these two URLs cover all the rules or not. You may need to examine the source code for each rule to find out how it works.

+4
source

If you are using an Xcode script, you should use oclint_args as follows:

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

in this example, I change the LONG_LINE rule to 150 characters

+4
source

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

Here is an example file that sets up several 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 
+4
source

All Articles