Danger plugins can help improve something we do every day: code reviews. Code reviews inside pull requests help you to keep the code quality high. However, it’s often that a comment contains feedback which could have been automated. Some examples:
- Missing documentation
- You might want to use
- Avoid using Force casts
Although it will cost you some time, in the beginning, it will save you a lot of time in the end.Exclusive discount for readers of SwiftLeeThere’s always new tricks, tips, and skills to learn with Swift, so expand your insight with expert-authored books and videos from Manning. Here’s a special 40% off discount to dive into amazing Swift books and videos today. Use code psswift40 at checkout to get 40% off any Manning book or liveVideo.
What is Danger?
Danger is an integration which runs during your CI process and gives teams the chance to automate common code review chores. It’s available as a Ruby GEM, NPM module and as a Swift Package Manager module. Kind of the same as Fastlane you set up a
Dangerfile per-project. The
Dangerfilecontains a collection of home-grown rules specific to your project.
- Danger runs on: Circle, Travis, Jenkins, Buildkite, BuddyBuild, Semaphore, TeamCity, Xcode Bots, Drone, Surf and Bitrise.
- Chats back on: GitHub, GitLab and Bitbucket.
- Is able to handle diffs from: Git.
Although the Swift version of Danger is improving fast, with this blog post I’m focussing on the Ruby version.
How to install Danger?
My focus on this blog post is fully on useful available plugins. The Getting Started page is a great and clear way to set up your project with Danger.
Danger plugins to automate code reviews
Danger was built to be a small core, which allows the community to extend her DSL via gems as plugins. As a result of this, there’s a lot of plugins to choose from. Let’s highlight a few of them which add value to your Swift, iOS, and Mac projects.
With over 11K stars on Github, you can call SwiftLint a popular framework. SwiftLint is a tool to enforce Swift style and conventions, loosely based on GitHub’s Swift Style Guide. The Danger SwiftLint plugin combines the best of both worlds and shows any linter errors or warnings inside the Danger comment. Oh, and good to know: this plugin is integrated by default inside Danger-Swift.
As the title already point out, this Danger plugin is generating a summary of your Xcode build. It includes occurred errors and warnings, as well as test results.
Showing code coverage with Xcov
An often placed comment on code reviews is related to tests. Sometimes tests are not added or the applied code changes affect the code coverage in a negative way. The Xcov plugin allows you to set a minimum required code coverage and will fail CI if needed. It also shows a list of changed files and their related code coverage.
Can I see some example implementations using Danger plugins?
Yes, you can! An overview of some examples is available at the Danger website. These are open source examples from companies like WeTransfer and Artsy, as well as open source frameworks like Moya and CocoaPods.
This all should be enough to get yourself started with integrating Danger in your CI system. Although it will cost you some time, in the beginning, it will save you a lot of time in the end.