/danger-swift-commit-lint

A Danger-Swift plugin to check commit messages.

Primary LanguageSwiftMIT LicenseMIT

Commit Lint For Danger-Swift

License

A danger-swift plugin to check each commit messages on the branch. This project is inspired by danger-commit-lint and its commit linting rules are ported too.

Installation

Add DangerSwiftCommitLint to your Package.file

.package(url: "https://github.com/AppDifferentia/danger-swift-commit-lint", from: "0.0.1")

Usage

Simply add the following lines to your Dangerfile.swift

import Danger

let danger = Danger()

//...

let commitLint = DangerSwiftCommitLint(danger: danger)
commitLint.check()

That will check each commit in the PR to ensure the following is true:

By default, Commit Lint fails, but you can configure this behavior.

E.g.

import Danger

let danger = Danger()

//...

let configuration = DangerSwiftCommitLint.Configuration(warn: .all)
let commitLint = DangerSwiftCommitLint(danger: danger, configuration: configuration)
commitLint.check()

Configuration

The commit lint can be configured with following 5 parameters.

  • disabled: can be .all or .selected([ ... ]), see Configuration.swift
  • warn: can be .all or .selected([ ... ]), see Configuration.swift
  • fail: can be .all or .selected([ ... ]), see Configuration.swift
  • limit: limits the number commits to lint. E.g. limit: 1 will limit the commit to the oldest commit on the branch
  • custom: allow caller to pass an array of custom linter that conforms to CommitLint protocol

E.g.

struct Configuration {

    init(
        disabled: CommitLintSelection = .selected([]),
        warn: CommitLintSelection = .selected([]),
        fail: CommitLintSelection = .all,
        limit: Int = 0,
        custom: [CommitLint.Type] = []
    ) {
        // ...
    }

}