As well as that I was hoping to find something I could use something to enforce a style guides on my code, because I know most editors do a poor job of this task.
Compiling is linting…
This is easy to validate in most situations but when you get to a reasonably large code base, it gets harder. When you are changing code/interfaces of classes it gets harder.
As well as being able to check the syntax and general correctness of your code, the Clang compiler does some static/semantic analysis of your code.
There is even Xcode support.
Once you get passed the CLang analysers you still be hungry for more tools to keep your code clean. There are open source projects to produce lints/static analysers for Objective-C.
As far as linting is concerned I’ve found a couple of projects.
OCLint says it is:
"A static code analysis tool for improving quality and reducing defects by inspecting C, C++ and Objective-C code"
The project has been around since the 1st of January 2013, as of writing it had hit 0.10.2. It hasn’t had the most consistent of release schedules but does seem to getting a lot of interest from the wider Github community.
It’s written in C++ primarily, so it’s got the potential to be cross platform if you were in the market to run static analysis on non-Mac hardware. Though I haven’t confirmed that yet.
Infer is tool built by Facebook which is:
"A tool to detect bugs in Android and iOS apps before they ship".
It’s relatively new (first release being the 11th of June 2015). It’s written in OCaml, runs on a Linux box, but there are no guarantees about it’s perform on code bases outside Facebook.
The only real player in town for beautifying/enforcing style seems to be Uncrustify. The main aim of the project according to it’s creators is to:
"Create a highly configurable, easily modifiable source code beautifier"
I’ve heard great things about Uncrustify, the C++ community really seem to appreciate it, so I’m looking forward to being able to finally use it myself.
Swift is the future of iOS and Mac. I’ve been experimenting a little bit with the language over the last while as well, Objective-C is still my main focus, but I get tempted by all the great things I hear on podcasts…etc
As far as linters are concerned the two main players are:
Unlike the Objective-C linters I found, SwiftLint is written itself in Swift. This project was started on the 18th May 2015. It’s based on the Github Swift Style Guide, so you know it’s opinions are based on some solid hard won experience.
Tinker, tailor, solider, spy… this linter is written in Java. Which means it’s definitely cross platform. Which gives you the options such as; say you had a centralized source control system and wanted to run a linter on a pre-commit hook. The project had its first release on the 19th September 2015, so a little later to the game than SwiftLint, but both are basically spring chickens. I don’t know how well Tailor would work if you wanted to integer with a development environment though.
This is by no means an exhaustive list. There are many tools coming out everyday to help with code quality (more for Swift than Objective-C obviously). As time goes by, and as I discover better tools, I’ll likely write about this topic again.
Below are links to web pages/articles I used to create this article.
- Title image based on “Window Cleaning In Protective Rubber Gloves Washing Windows” by Cade Martin, Dawn Arlotta
- Facebook static analyser “Infer”
- Objective-C linter; “OCLint”
- Swift Linter; “SwiftLint”
- Swift Linter; “tailor”
- The code style checker “Uncrustify”
- The built in “Clang Analyser”