OCLint rules and result analysis

OCLint is used to do C, c++ and Objective-c static code analysis tools. The installation and use of OCLint is described in the OCLint installation and use. After running OCLint, according to the rules to understand the results, analysis and modification of the code. Some warning
sometimes code, do not need to change immediately, but there is a warning where still looked very uncomfortable, would you need to know how to or ignore some rules to ban this time, to eliminate the warning.

OCLint rule

There are 67 inspection rules
http://docs.oclint.org/en/stable/rules/index.html OCLint in the latest
, mainly for the nil value of the cocoa examination, obj examination, type conversion, null check parameters concise syntax check, size, and don’t use the parameters and variables of inspection.
is mainly divided into 9 categories:

Basic Cocoa Empty Migration Redundant Size Naming Convention Unused

Before we can use the command: oclint-json-compilation-database -e parameters to ignore the specified file, such as ignoring the Pods folder under the check:

Oclint-json-compilation-database -e Pods —o=report.html

You can also use -rc to change the default value of the check rules:

Oclint-json-compilation-database —rc=LONG_LINE=200 -o=report.html

If you want to ban the use of a rule you can use the command -disable-rule:

Oclint-json-compilation-database -disable-rule=LongLine

This allows you to disable the LongLine check in Size.

OCLint result analysis

OCLint static analysis results, the warning level is reduced from P1, P2, P3, can be generated according to the report to find the corresponding rules, as well as changes in recommendations.
, for example, is a warning message:

/SuperLoggerPreviewView.m:165:5: bitwise operator in... / conditional [basic|P2]...

… /… /SuperLoggerPreviewView.m:165:5: means for generating a warning file and the corresponding line number.

Bitwise operator in conditional: description information.
[basic|P2] this information refers to the type of inspection rules, corresponding to check the rules of the 9 categories, P2 is the level of warning basic

Rule Index can be found in the first classification Basic bitwiseoperatorinconditional, is the need to understand the rules of information:

OCLint rules and result analysis
Rule Index

Check for OCLint

Sometimes, in the case of known piece of code will produce OCLint warning, but because of other reasons, we can modify the code, or not found when better modification, can prevent OCLint in the code check.

1 Notes

You can use the annotation method to prohibit the OCLint check:

Attribute (annotate (“oclint:suppress[unused method parameter]”))

For example, we know that a parameter is not used, and do not want to produce warning information can be written:

- (IBAction) turnoverValueChanged: (ID) __attribute__ ((annotate ("oclint:suppress[unused method parameter]"))) {sender int i; won't suppress this one [self / / calculateTurnover];}

Annotations for the method can be written like this:

Bool (__attribute__ (annotate ("oclint:suppress"))) aMethod (int aParameter within this method) {/ / warnings are suppressed at all unused aParameter variable and / / like empty if statement if return true (1) {}};

2! OCLint
can also be used OCLint notes, / /! Do not let OCLint check.

Void a (int unusedLocalVariable) {OCLINT}; / /!

Comments should be written on the corresponding line to prohibit the corresponding check, such as the empty if/else check for comments:

If (true) / / OCLint / / it is! {empty}