https://github.com/cuonglm/gocmt
Add missing comment on exported function, method, type, constant, variable in go file
https://github.com/cuonglm/gocmt
comment go golang golang-library golang-tools lint
Last synced: about 1 year ago
JSON representation
Add missing comment on exported function, method, type, constant, variable in go file
- Host: GitHub
- URL: https://github.com/cuonglm/gocmt
- Owner: cuonglm
- License: other
- Created: 2016-10-05T03:53:56.000Z (over 9 years ago)
- Default Branch: main
- Last Pushed: 2023-08-30T15:47:02.000Z (almost 3 years ago)
- Last Synced: 2025-04-10T01:15:52.936Z (about 1 year ago)
- Topics: comment, go, golang, golang-library, golang-tools, lint
- Language: Go
- Size: 34.2 KB
- Stars: 175
- Watchers: 2
- Forks: 28
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# gocmt - Add missing comment on exported function, method, type, constant, variable in go file

[](https://pkg.go.dev/github.com/cuonglm/gocmt)
[](https://goreportcard.com/report/github.com/cuonglm/gocmt)
# Installation
For go1.15 and below:
```sh
go get -u github.com/cuonglm/gocmt
```
For go1.16 and above:
```sh
go install github.com/cuonglm/gocmt@latest
```
# Why gocmt
Some of my projects have many files with exported fields, variables, functions missing comment, so lint tools will complain.
I find a way to auto add missing comment to them, just to pass the lint tools but nothing existed.
So `gocmt` comes in.
# Usage
```sh
$ gocmt -h
usage: gocmt [flags] [file ...]
-d string
Directory to process
-i Make in-place editing
-t string
Comment template (default "...")
```
# Example
```sh
$ cat testdata/main.go
package p
var i = 0
var I = 1
var c = "constant un-exported"
const C = "constant exported"
type t struct{}
type T struct{}
func main() {
}
func unexport(s string) {
}
func Export(s string) {
}
func ExportWithComment(s string) {
}
```
Using `gocmt` give you:
```sh
$ gocmt testdata/main.go
package p
var i = 0
// I ...
var I = 1
var c = "constant un-exported"
// C ...
const C = "constant exported"
type t struct{}
// T ...
type T struct{}
func main() {
}
func unexport(s string) {
}
// Export ...
func Export(s string) {
}
// ExportWithComment ...
func ExportWithComment(s string) {
}
```
Default template is `...`, you can change it using `-t` option.
# Author
Cuong Manh Le
# License
See [LICENSE](https://github.com/cuonglm/gocmt/blob/main/LICENSE)