OCLint
OCLint is a static code analysis tool for improving quality and reducing defects by inspecting C, C++ and Objective-C code and looking for potential problems like:
- Possible bugs – empty if/else/try/catch/finally statements
- Unused code – unused local variables and parameters
- Complicated code – high cyclomatic complexity, NPath complexity and high NCSS
- Redundant code – redundant if statement and useless parentheses
- Code smells – long method and long parameter list
- Bad practices – inverted logic and parameter reassignment
Installing OCLint via Homebrew:
$ brew tap oclint/formulae
$ brew install oclint
Refer to your ios project run below commands,
$ brew tap oclint/formulae
$ brew install oclint
Refer to github repo for more info.
Execute oclint
command :
$ oclint
Terminal should give message like oclint: Not enough positional command line arguments specified!
Lets run the oclint in our Xcode project now.
Checking Single File
OCLint checks a single file using the following format:
oclint [options] <source> -- [compiler flags]
Assume that I have Sample.m file and I want to check them,
$ oclint Sample.m
Checking Multiple Files
OCLint checks a multiple files using the following format:
oclint [options] <source0> [... <sourceN>] -- [compiler flags]
However, each source file may have different compiler flags. In this case, by reading from the compilation database, OCLint can recognize the list of source files for analysis, along with the compiler flags used for each time during the compilation phase. It can be considered as a condensed Makefile. So, in this case
oclint -p <build-path> [other options] <source0> [... <sourceN>]
Update
To update the brew package, use brew update first:
$ brew update
$ brew upgrade oclint
For further information here is the documentation.