What is SwiftLint?

SwiftLint is a tool to enforce Swift style and conventions, loosely based on GitHub’s Swift Style Guide.

Why do we need to integrate SwiftLint?

When you are working with a team of developers in a project, it’s become difficult to maintain codebase styling and syntax. That is why we have lint or a linter — A tool to analyze source code to make sure it matches whatever style guide you have agreed on in your team.

In the Swift world, we have SwiftLint, created by serial Swift community contributor JP Simard and others. SwiftLint hooks into Apple’s own SourceKit framework to parse your Swift code, which means it supports the full range of Swift syntax and remains up to date as Swift continues to evolve.

How to integrate SwiftLint in the Project?

  1. Installation of SwiftLint
  2. Integration with Xcode
  3. Verify our Integration
  4. Configuration of Rules

STEP 1: Installation of SwiftLint

Using Homebrew:

brew install swiftlint

Using CocoaPods:

Simply add the following line to your Podfile:

pod 'SwiftLint'

This will download the SwiftLint binaries and dependencies in Pods/ during your next pod install execution and will allow you to invoke it via ${PODS_ROOT}/SwiftLint/swiftlint in your Script Build Phases.

Using Mint:

$ mint install realm/SwiftLint

Using a pre-built package:

You can also install SwiftLint by downloading SwiftLint.pkg from the latest GitHub release and running it. During the installation, you may see this alert

Image for post

SwiftLint.pkg Installation Alert

In that case, you need to grant permission to run SwiftLint.pkg on your system. To do that, navigate to  Menu > System Preferences... > Security & Privacy > General and click Open Anyway button

Image for post

#github #ios #swift #swiftlint #style-guides

How to enforce Swift style and conventions into the project using SwiftLint?
7.05 GEEK