Code Review Tools, Configurations, and Recommendations
- SwiftLint
- https://github.com/realm/SwiftLint
- Configuration:
.swiftlint.yml- Setup options:
ln -s swiftlint.yml .swiftlint.ymlmv swiftlint.yml .swiftlint.yml
- Setup options:
swiftlint --config .swiftlint.yml- oclint
- https://github.com/oclint/oclint
- Configuration:
.oclint- Setup options:
ln -s oclint.yml .oclintmv oclint.yml .oclint
- Setup options:
xcodebuild -project MyProject.xcodeproj -scheme MyScheme -sdk macosx -configuration Debug build | xcpretty -r json-compilation-database -o compile_commands.json
oclint-json-compilation-database
oclint -rc CYCLOMATIC_COMPLEXITY=10 -rc LONG_CLASS=1000OCLint requires a "JSON compilation database" files to perform it's linting. This file contains a list of the Xcode build plan with the compiler flags that Xcode will pass to the compiler for each file. This complicates using oclint since we have to first run a
buildpass on the project, post-process the output usingxcpretty, then post-process thexcprettyoutput using theoclint-json-compilation-databasetool.
gem install xcpretty- swift-format
- https://github.com/apple/swift-format
- Methodology
- Parses code into AST then outputs AST through pretty printing
- Strips all custom formatting
- Can modify output formatting via configuration
- Configuration:
.swift-format.json- Setup options:
ln -s swift-format.json .swift-format.jsonmv swift-format.json .swift-format.json
- Setup options:
swiftformat **/*.swift- SwiftFormat
- https://github.com/nicklockwood/SwiftFormat
- Methodology
- Text parser
- Operates on line groups
- Can ignore some text via configuration
- Configuration:
.swiftformat- Rules
- Setup options:
ln -s swiftformat.cfg .swiftformatmv swiftformat.cfg .swiftformat
swiftformat **/*.swift- clang-format
- https://clang.llvm.org/docs/ClangFormatStyleOptions.html
- Standard with Xcode
- Configuration:
.clang-format- Setup options:
ln -s clang-format.yml .clang-formatmv clang-format.yml .clang-format
- Setup options:
xcrun clang-format -i **/*.[hm]- Apple sample code:
- Style guides based on Apple documentation and sample code