Knyt
February 23, 2014
After writing a Ruby tool that checks for the Apache license on Objective-C files, I’ve now written a tool called Knyt that checks whether Objective-C files conform to the New York Times Objective-C style guide. I’ve been writing Objective-C in this style for the last few months, but I thought it would be useful to be able to check over my code automatically and find parts where I’m not conforming. It’s a bit like unit tests, but for the source code rather than compiled code.
Knyt works by scanning a directory for Objective-C files (it can also scan subdirectories or just one file), reads them and then checks them against a set of rules, which in most cases are regular expressions of varying complexity. It then outputs any places where the rules aren’t being abided properly.
The full set of rules hasn’t been implemented because many rules are vague (‘the ternary operator should only be used when it improves clarity’) or can’t be implemented context free (dot notation being used for accessing methods rather than properties, for example) however the majority of the rules that affect the style have been implemented.
In order to use Knyt you will firstly need to clone the Xcode project from GitHub. It compiles correctly on Mavericks (and presumably Mountain Lion) using Xcode 5 in its standard configuration. If you want to test it directly from Xcode you will need to edit the scheme’s arguments and change them to use your code directory. Alternatively, build the project and use the ‘Show in Finder’ option to find the produced executable. Whilst the project is still in alpha I won’t be adding an executable on GitHub.