https://github.com/elliotxx/gocmt
Read Go code, better comment. Power by AI.
https://github.com/elliotxx/gocmt
Last synced: 6 months ago
JSON representation
Read Go code, better comment. Power by AI.
- Host: GitHub
- URL: https://github.com/elliotxx/gocmt
- Owner: elliotxx
- Created: 2024-04-11T02:52:11.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-04-18T09:14:53.000Z (over 1 year ago)
- Last Synced: 2025-02-16T05:41:26.648Z (8 months ago)
- Language: Go
- Homepage:
- Size: 44.9 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## gocmt
你对 go 代码质量有更高的要求吗?那么注释一定是必不可少的。
`gocmt` 支持检查、补充、优化 go 代码注释,同时支持计算代码注释率,用于衡量项目是否有充足的注释说明。
## Installation
```bash
go install github.com/elliotxx/gocmt@latest
```## Usage
```bash
$ gocmt -h
Usage: gocmt [options]Options:
-f string
File or directory containing Go code.
-c string
Specify a commit hash or reference (e.g., HEAD, HEAD^, commitID1...commitID2)
-n int
Number of concurrent executions
-h bool
Show this help message and exitExamples:
gocmt -f /path/to/example.go
gocmt -f /path/to/dir/
gocmt -c HEAD
gocmt -c HEAD^
gocmt -c commitID1...commitID2
```## Example
The go source code of no comment to be processed:
```go
$ cat handler.go
package handlerfunc printDebugf(format string, args ...interface{}) {
}type ErrorResponse struct {
}func (e *ErrorResponse) String() string {
}func Respond(w http.ResponseWriter, code int, src interface{}) {
}func Error(w http.ResponseWriter, code int, err error, msg string) {
}func JSON(w http.ResponseWriter, code int, src interface{}) {
}type Handler struct {}
func (h Handler) Routes() *router.Router {
}func (h Handler) Run(port int) error {
}func (h Handler) getUser(w http.ResponseWriter, r *http.Request, id int) {
}func (h Handler) getUsers(w http.ResponseWriter, r *http.Request) {
}func (h Handler) createUser(w http.ResponseWriter, r *http.Request) {
}
```Execute `gocmt`:
```bash
$ gocmt -f handler.go
» Comments will be added to these go files soon:
handler.go» Processing handler.go...
✔ Processed file handler.go
Progress: 1/1, 100.00%All files processed.
```After processing with `gocmt`:
```go
$ cat handler.go
package handler// printDebugf printing debug information in a formatted manner.
func printDebugf(format string, args ...interface{}) {
}type ErrorResponse struct {
}// String returns the error message in string format.
func (e *ErrorResponse) String() string {
}// Respond send a response with a given status code and source data.
func Respond(w http.ResponseWriter, code int, src interface{}) {
}// Error send an error response with a given status code, error, and message.
func Error(w http.ResponseWriter, code int, err error, msg string) {
}// JSON send a JSON response with a given status code and source data.
func JSON(w http.ResponseWriter, code int, src interface{}) {
}type Handler struct {}
// Routes returns the router with all the routes configured.
func (h Handler) Routes() *router.Router {
}// Run starts the HTTP server on the given port and listens for incoming requests.
func (h Handler) Run(port int) error {
}// getUser handles the GET request for fetching a single user by ID.
func (h Handler) getUser(w http.ResponseWriter, r *http.Request, id int) {
}// getUsers handles the GET request for fetching all the users.
func (h Handler) getUsers(w http.ResponseWriter, r *http.Request) {
}// createUser handles the POST request for creating a new user.
func (h Handler) createUser(w http.ResponseWriter, r *http.Request) {
}
```If you forgot to add comments in the latest git commit, you can do this:
```bash
$ gocmt -c HEAD^# Or you can specify commit:
$ gocmt -c
# And this:
$ gocmt -c ...
```## TODO
- [x] 通过 KIMI API 自动补充注释
- [x] 文件或者目录作为输入
- [x] 跳过已存在的注释
- [x] 日志输出
- [x] 输出进度条
- [x] 忽略单元测试
- [x] 并发执行
- [x] 识别 git diff 对最近一次变更受影响的文件补充注释
- [ ] 支持补充 godoc example
- [ ] 支持补充 openapi 格式的注释
- [ ] 支持 -V 查看版本号
- [ ] 优化 prompt 返回结果,不需要空格和回车
- [ ] 支持 homebrew 安装
- [ ] 支持 --exclude 用来忽略指定目录
- [ ] 失败重试机制
- [ ] 限制输入和输出的长度
- [ ] 支持 -f 指定多个路径
- [ ] 执行前 token 消耗评估
- [ ] 配置 maxLineWidth
- [ ] 扫描不合规的注释
- [ ] 扫描结果打标
- [ ] 计算注释率