gocmt

command module
Version: v0.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 28, 2021 License: BSD-3-Clause Imports: 13 Imported by: 0

README

gocmt - Add missing comment on exported function, method, type, constant, variable in go file

Build status Go Reference Go Report Card

Installation

For go1.15 and below:

go get -u github.com/cuonglm/gocmt

For go1.16 and above:

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

$ gocmt -h
usage: gocmt [flags] [file ...]
  -d string
    	Directory to process
  -i	Make in-place editing
  -t string
    	Comment template (default "...")

Example

$ 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:

$ 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 cuong.manhle.vn@gmail.com

License

See LICENSE

Documentation

Overview

gocmt adds missing comments on exported identifiers in Go source files.

Usage:

gocmt [-i] [-p] [-t "comment template"] [-d dir]

This tools exists because I have to work with some existed code base, which is lack of documentation for many exported identifiers. Iterating over them is time consuming and maybe not suitable at a stage of the project. So I wrote this tool to quickly bypassing CI system. Once thing is settle, we can lookback and fix missing comments.

You SHOULD always write documentation for all your exported identifiers.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL