Commit Lint For Danger-Swift
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:
- Commit subject begins with a capital letter (
SubjectCapitalLetter.swift
) - Commit subject is more than one word (
SubjectWord.swift
) - Commit subject is no longer than 50 characters (
SubjectLength.swift
) - Commit subject does not end in a period (
SubjectPeriod.swift
) - Commit subject and body are separated by an empty line (
BodyEmptyLine.swift
)
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([ ... ])
, seeConfiguration.swift
warn
: can be.all
or.selected([ ... ])
, seeConfiguration.swift
fail
: can be.all
or.selected([ ... ])
, seeConfiguration.swift
limit
: limits the number commits to lint. E.g.limit: 1
will limit the commit to the oldest commit on the branchcustom
: allow caller to pass an array of custom linter that conforms toCommitLint
protocol
E.g.
struct Configuration {
init(
disabled: CommitLintSelection = .selected([]),
warn: CommitLintSelection = .selected([]),
fail: CommitLintSelection = .all,
limit: Int = 0,
custom: [CommitLint.Type] = []
) {
// ...
}
}