Skip to content

Commit 8e4702e

Browse files
authored
Merge pull request #6 from AppDifferentia/update-document
[Doc] Update documentation
2 parents 82b0732 + a728c50 commit 8e4702e

23 files changed

+131
-52
lines changed

README.md

Lines changed: 77 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,77 @@
1-
# danger-swift-commit-lint
2-
A Danger-Swift plugin to check commit messages
1+
# Commit Lint For Danger-Swift
2+
3+
A [`danger-swift`]("https://github.com/danger/swift") plugin to check each commit messages on the branch. This project is inspired by [`danger-commit-lint`](https://github.com/jonallured/danger-commit_lint) and its commit linting rules are ported too.
4+
5+
## Installation
6+
7+
Add `DangerSwiftCommitLint` to your `Package.file`
8+
```Swift
9+
.package(url: "https://github.com/AppDifferentia/danger-swift-commit-lint", from: "0.0.1")
10+
```
11+
12+
## Usage
13+
14+
Simply add the following lines to your `Dangerfile.swift`
15+
16+
```Swift
17+
import Danger
18+
19+
let danger = Danger()
20+
21+
//...
22+
23+
let commitLint = DangerSwiftCommitLint(danger: danger)
24+
commitLint.check()
25+
```
26+
27+
That will check each commit in the PR to ensure the following is true:
28+
29+
- Commit subject begins with a capital letter (`Sources/DangerSwiftLint/CommitLint/SubjectCapitalLetter`)
30+
- Commit subject is more than one word (`Sources/DangerSwiftLint/CommitLint/SubjectWord`)
31+
- Commit subject is no longer than 50 characters (`Sources/DangerSwiftLint/CommitLint/SubjectLength`)
32+
- Commit subject does not end in a period (`Sources/DangerSwiftLint/CommitLint/SubjectPeriod`)
33+
- Commit subject and body are separated by an empty line (`Sources/DangerSwiftLint/CommitLint/BodyEmptyLine`)
34+
35+
By default, Commit Lint fails, but you can configure this behavior.
36+
37+
E.g.
38+
39+
```Swift
40+
import Danger
41+
42+
let danger = Danger()
43+
44+
//...
45+
46+
let configuration = DangerSwiftCommitLint.Configuration(warn: .all)
47+
let commitLint = DangerSwiftCommitLint(danger: danger, configuration: configuration)
48+
commitLint.check()
49+
```
50+
51+
## Configuration
52+
53+
The commit lint can be configured with following 5 parameters.
54+
55+
- `disabled`: can be `.all` or `.selected([ ... ])`, see [`DangerSwiftCommitLint/Configuration`]("DangerSwiftCommitLint/Configuration")
56+
- `warn`: can be `.all` or `.selected([ ... ])`, see [`DangerSwiftCommitLint/Configuration`]("DangerSwiftCommitLint/Configuration")
57+
- `fail`: can be `.all` or `.selected([ ... ])`, see [`DangerSwiftCommitLint/Configuration`]("DangerSwiftCommitLint/Configuration")
58+
- `limit`: limits the number commits to lint. E.g. `limit: 1` will limit the commit to the oldest commit on the branch
59+
- `custom`: allow caller to pass an array of custom linter that conforms to `DangerSwiftCommitLint.CommitLint` protocol
60+
61+
E.g.
62+
63+
```Swift
64+
struct Configuration {
65+
66+
init(
67+
disabled: CommitLintSelection = .selected([]),
68+
warn: CommitLintSelection = .selected([]),
69+
fail: CommitLintSelection = .all,
70+
limit: Int = 0,
71+
custom: [CommitLint.Type] = []
72+
) {
73+
// ...
74+
}
75+
76+
}
77+
```

Sources/DangerSwiftCommitLint/CommitChecker/BodyEmptyLine.swift renamed to Sources/DangerSwiftCommitLint/CommitLint/BodyEmptyLine.swift

File renamed without changes.

Sources/DangerSwiftCommitLint/CommitChecker/CommitLint.swift renamed to Sources/DangerSwiftCommitLint/CommitLint/CommitLint.swift

File renamed without changes.

Sources/DangerSwiftCommitLint/CommitChecker/GitCommitMessage.swift renamed to Sources/DangerSwiftCommitLint/CommitLint/GitCommitMessage.swift

File renamed without changes.

Sources/DangerSwiftCommitLint/CommitChecker/SubjectCapitalLetter.swift renamed to Sources/DangerSwiftCommitLint/CommitLint/SubjectCapitalLetter.swift

File renamed without changes.

Sources/DangerSwiftCommitLint/CommitChecker/SubjectLength.swift renamed to Sources/DangerSwiftCommitLint/CommitLint/SubjectLength.swift

File renamed without changes.

Sources/DangerSwiftCommitLint/CommitChecker/SubjectPeriod.swift renamed to Sources/DangerSwiftCommitLint/CommitLint/SubjectPeriod.swift

File renamed without changes.

Sources/DangerSwiftCommitLint/CommitChecker/SubjectWord.swift renamed to Sources/DangerSwiftCommitLint/CommitLint/SubjectWord.swift

File renamed without changes.

Sources/DangerSwiftCommitLint/Configuration.swift

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,65 +2,66 @@ import Foundation
22

33
public extension DangerSwiftCommitLint {
44
/// All commit checkers provided by `DangerSwiftCommitLint`
5-
enum CommitCheckerType: CaseIterable, Hashable {
6-
/// Commit subject and body are separated by an empty line (`CommitChecker/BodyEmptyLineCheck`)
5+
enum CommitLintType: CaseIterable, Hashable {
6+
/// Commit subject and body are separated by an empty line (`CommitLint/BodyEmptyLineCheck`)
77
case bodyEmptyLine
8-
/// Commit subject begins with a capital letter (`CommitChecker/SubjectCapCheck`)
8+
/// Commit subject begins with a capital letter (`CommitLint/SubjectCapCheck`)
99
case subjectCapitalLetter
10-
/// Commit subject is no longer than 50 characters (`CommitChecker/SubjectLengthCheck`)
10+
/// Commit subject is no longer than 50 characters (`CommitLint/SubjectLengthCheck`)
1111
case subjectLength
12-
/// Commit subject does not end in a period (`CommitChecker/SubjectPeriodCheck`)
12+
/// Commit subject does not end in a period (`CommitLint/SubjectPeriodCheck`)
1313
case subjectPeriod
14-
/// Commit subject is more than one word (`CommitChecker/SubjectWordCheck`)
14+
/// Commit subject is more than one word (`CommitLint/SubjectWordCheck`)
1515
case subjectWord
1616
}
1717

1818
/// Checker selection
19-
enum CommitCheckerSelection {
19+
enum CommitLintSelection {
2020
/// Select all checkers
2121
case all
2222
/// Select a set of checkers
23-
case selected(Set<CommitCheckerType>)
23+
case selected(Set<CommitLintType>)
2424
}
2525

26+
/// Configuration for `DangerSwiftCommitLint`
2627
struct Configuration {
2728
let limit: Int
2829

29-
private let disabled: CommitCheckerSelection
30-
private let warn: CommitCheckerSelection
31-
private let fail: CommitCheckerSelection
32-
private let customCheckers: [CommitLint.Type]
30+
private let disabled: CommitLintSelection
31+
private let warn: CommitLintSelection
32+
private let fail: CommitLintSelection
33+
private let custom: [CommitLint.Type]
3334

3435
/// Initialize the configuration.
3536
/// - Parameters:
36-
/// - disabled: The selected checks to skip.
37-
/// - warn: The selected checks to warn on.
38-
/// - fail: The selected checks to fail on.
37+
/// - disabled: The selected commit lint to skip.
38+
/// - warn: The selected commit lint to warn on.
39+
/// - fail: The selected commit lint to fail on.
3940
/// - limit: The number of commits to check.
40-
/// - customCheckers: An array of custom checkers.
41+
/// - customCheckers: An array of custom checkers. This array will be added to all checkers.
4142
public init(
42-
disabled: CommitCheckerSelection = .selected([]),
43-
warn: CommitCheckerSelection = .selected([]),
44-
fail: CommitCheckerSelection = .all,
43+
disabled: CommitLintSelection = .selected([]),
44+
warn: CommitLintSelection = .selected([]),
45+
fail: CommitLintSelection = .all,
4546
limit: Int = 0,
46-
customCheckers: [CommitLint.Type] = []
47+
custom: [CommitLint.Type] = []
4748
) {
4849
self.disabled = disabled
4950
self.warn = warn
5051
self.fail = fail
5152
self.limit = limit
52-
self.customCheckers = customCheckers
53+
self.custom = custom
5354
}
5455
}
5556
}
5657

5758
extension DangerSwiftCommitLint.Configuration {
5859
static var defaultCheckers: [CommitLint.Type] {
59-
DangerSwiftCommitLint.CommitCheckerType.allCases.map(\.type)
60+
DangerSwiftCommitLint.CommitLintType.allCases.map(\.type)
6061
}
6162

6263
var allCheckers: [CommitLint.Type] {
63-
Self.defaultCheckers + customCheckers
64+
Self.defaultCheckers + custom
6465
}
6566

6667
var disabledCheckers: [CommitLint.Type] {
@@ -96,7 +97,7 @@ extension DangerSwiftCommitLint.Configuration {
9697
}
9798
}
9899

99-
private extension DangerSwiftCommitLint.CommitCheckerType {
100+
private extension DangerSwiftCommitLint.CommitLintType {
100101
var type: CommitLint.Type {
101102
switch self {
102103
case .bodyEmptyLine: return BodyEmptyLine.self

Sources/DangerSwiftCommitLint/DangerSwiftCommitLint.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import Danger
22
import Foundation
33

4+
/// A protocol for dependency inject `DangerDSL`.
5+
/// - `DangerSwiftCommitLint` only require these interfaces.
46
public protocol DangerDSLProviding {
57
var git: Git { get }
68

@@ -10,6 +12,7 @@ public protocol DangerDSLProviding {
1012

1113
extension DangerDSL: DangerDSLProviding {}
1214

15+
/// A Danger-Swift plugin to lint each commit in the PR. See `Configuration` for linter configuration.
1316
public final class DangerSwiftCommitLint {
1417
private enum Constants {
1518
static let disableAllChecksMessage = "All checks were disabled, nothing to do."
@@ -22,7 +25,7 @@ public final class DangerSwiftCommitLint {
2225
/// - Parameters:
2326
/// - danger: An instance of `Danger.DangerDSL`.
2427
/// - configuration: Linter configuration.
25-
public init(danger: DangerDSLProviding = Danger(), configuration: Configuration) {
28+
public init(danger: DangerDSLProviding = Danger(), configuration: Configuration = .init()) {
2629
self.danger = danger
2730
self.configuration = configuration
2831
}

0 commit comments

Comments
 (0)