Skip to content

Commit 5086ea3

Browse files
feat: initial commit
0 parents  commit 5086ea3

13 files changed

+999
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Bin Directory
2+
/bin

LICENSE.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2021 Muthu Krishnan
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

+119
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# commitlint
2+
3+
commitlint checks if your commit messages meets the [conventional commit format](https://www.conventionalcommits.org/en/v1.0.0/)
4+
5+
[![PkgGoDev](https://pkg.go.dev/badge/github.com/conventionalcommit/parser)](https://pkg.go.dev/github.com/conventionalcommit/parser)
6+
7+
### Installation
8+
9+
```bash
10+
# Install commitlint
11+
go install github.com/conventionalcommit/commitlint/cmd/commitlint@latest
12+
13+
# test commitlint - error case
14+
echo "fear: do not fear for commit message" | commitlint lint
15+
# will show error message like
16+
# ❌ type: 'fear' is not allowed, you can use one of [feat fix docs style refactor perf test build ci chore revert merge]
17+
18+
# test commitlint - valid case
19+
echo "feat: good commit message" | commitlint lint
20+
# ✓ commit message
21+
```
22+
23+
### Enable in Git Repo
24+
25+
```bash
26+
# enable for single repo
27+
commitlint create hook # from repo directory
28+
29+
# enable for globally for all repos
30+
commitlint create hook --global
31+
```
32+
33+
### Benefits using commitlint
34+
35+
- [Why Use Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/#why-use-conventional-commits)
36+
37+
### Commit Types
38+
39+
​ Commonly used commit types from [Conventional Commit Types](https://github.com/commitizen/conventional-commit-types)
40+
41+
| Type | Description |
42+
|:---------|:---------------------------------------------------------------------------------|
43+
| feat | A new feature |
44+
| fix | A bug fix |
45+
| docs | Documentation only changes |
46+
| style | Changes that do not affect the meaning of the code (white-space, formatting etc) |
47+
| refactor | A code change that neither fixes a bug nor adds a feature |
48+
| perf | A code change that improves performance |
49+
| test | Adding missing tests or correcting existing tests |
50+
| build | Changes that affect the build system or external dependencies |
51+
| ci | Changes to our CI configuration files and scripts |
52+
| chore | Other changes that don't modify src or test files |
53+
| revert | Reverts a previous commit |
54+
| merge | Merges a branch |
55+
56+
### Library
57+
58+
#### Config Precedence
59+
60+
- `commitlint.yaml` config file in current directory
61+
- config file passed with `--config` command-line argument
62+
- [default config](#default-config)
63+
64+
#### Message Precedence
65+
66+
- `stdin` stream
67+
- commit message file passed with `--message` command-line argument
68+
- `.git/COMMIT_EDITMSG` in current directory
69+
70+
#### Default Config
71+
72+
```yaml
73+
header:
74+
min-length:
75+
enabled: true
76+
type: error
77+
value: 10
78+
max-length:
79+
enabled: true
80+
type: error
81+
value: 50
82+
types:
83+
enabled: true
84+
type: error
85+
value:
86+
- feat
87+
- fix
88+
- docs
89+
- style
90+
- refactor
91+
- perf
92+
- test
93+
- build
94+
- ci
95+
- chore
96+
- revert
97+
- merge
98+
scopes:
99+
enabled: false
100+
type: error
101+
value: []
102+
body:
103+
can-be-empty: true
104+
max-line-length:
105+
enabled: true
106+
type: error
107+
value: 72
108+
footer:
109+
can-be-empty: true
110+
max-line-length:
111+
enabled: true
112+
type: error
113+
value: 72
114+
```
115+
116+
### License
117+
118+
All packages are licensed under [MIT License](https://github.com/conventionalcommit/commitlint/tree/master/LICENSE.md)
119+

cmd/commitlint/cmd.go

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/urfave/cli/v2"
7+
)
8+
9+
func getApp() *cli.App {
10+
createCmd := &cli.Command{
11+
Name: "create",
12+
Usage: "helpers for initializing commitlint",
13+
Subcommands: []*cli.Command{
14+
{
15+
Name: "config",
16+
Usage: "creates default commitlint.yaml in current directory",
17+
Action: initConfCallback,
18+
},
19+
{
20+
Name: "hook",
21+
Usage: "creates commit hook and sets git config",
22+
Action: initHookCallback,
23+
Flags: []cli.Flag{
24+
&cli.BoolFlag{
25+
Name: "global",
26+
Aliases: []string{"g"},
27+
Usage: "sets git hook config in global`",
28+
},
29+
},
30+
},
31+
},
32+
}
33+
34+
lintCmd := &cli.Command{
35+
Name: "lint",
36+
Usage: "lints commit message",
37+
Action: lintCallback,
38+
Flags: []cli.Flag{
39+
&cli.StringFlag{
40+
Name: "config",
41+
Aliases: []string{"c", "conf"},
42+
Value: "",
43+
Usage: "optional config file `conf.yaml`",
44+
},
45+
&cli.StringFlag{
46+
Name: "message",
47+
Aliases: []string{"m", "msg"},
48+
Value: "",
49+
Usage: "path to git commit message `FILE`",
50+
},
51+
},
52+
}
53+
54+
versionCmd := &cli.Command{
55+
Name: "version",
56+
Usage: "prints commitlint version",
57+
Action: func(c *cli.Context) error {
58+
fmt.Println("commitlint - v0.1.0")
59+
return nil
60+
},
61+
}
62+
63+
return &cli.App{
64+
Name: "commitlint",
65+
Usage: "linter for conventional commits",
66+
Action: nil,
67+
Commands: []*cli.Command{lintCmd, createCmd, versionCmd},
68+
}
69+
}

0 commit comments

Comments
 (0)