首页 > 其他分享 >golang fmt && lint

golang fmt && lint

时间:2022-11-13 16:45:18浏览次数:52  
标签:golangci fmt lint cd golang && go

如何轻松使用格式化和静态检查工具

make fmt

make lint

 

1、go.mod 同级目录创建文件 Makefile

fmt:
    command -v gofumpt || (WORK=$(shell pwd) && cd /tmp && GO111MODULE=on go install mvdan.cc/gofumpt@latest && cd $(WORK))
    gofumpt -w -d .

lint:
    command -v golangci-lint || (WORK=$(shell pwd) && cd /tmp && GO111MODULE=on go install github.com/golangci/golangci-lint/cmd/[email protected] && cd $(WORK))
    golangci-lint run  -v

 

2、go.mod 同级目录创建文件 .golangci.toml

 

[run]
tests = false
concurrency = 4
skip-dirs = [ "vendor", "go" ]
timeout= "300s"

[run.output]
format = "tab"

[linters]
disable-all = true
enable = [
    "unconvert",
    "megacheck",
    #    "gosec",
    #    "gocyclo",
    "dupl",
    "misspell",
    "unparam",
    "unused",
    #    "deadcode",
    "typecheck",
    "ineffassign",
    "gochecknoinits",
    "gocritic",
    #    "godox",
    "gofmt",
    "gofumpt",
    "goimports",
    #    "lll",
]

# linter config
[linters-settings.dupl]
threshold = 300

[linters-settings.gocritic]
enabled-tags = [
    "diagnostic",
    "experimental",
    "opinionated",
    "performance",
    "style",
]
disabled-checks = [
    "dupImport",
    "ifElseChain",
    "octalLiteral",
    "whyNoLint",
    "wrapperFunc",
    "paramTypeCombine",
    "nilValReturn",
    "unnamedResult",
    "unnecessaryBlock",
    "commentedOutCode",
    "appendCombine",
    "truncateCmp",
    "yodaStyleExpr",
]

 

标签:golangci,fmt,lint,cd,golang,&&,go
From: https://www.cnblogs.com/xuweiqiang/p/16886255.html

相关文章

  • golang内存对齐的重要性
     结构体中字段类型的改变直接造成内存对齐结果的改变,是的占用内存空间也不一样packagemainimport( "fmt" "unsafe")funcmain(){ varxxstruct{ aboo......
  • golang:break,continue,return,goto使用区别
    break条件满足,跳出整个循环continue条件满足,跳出这次循环,但继续执行后面的循环return返回数据,结束当前函数或程序运行gotogo语言的goto可以无条件的转移到程序中指......
  • Golang:error包错误处理
    (目录)1、Golangerror包内建error接口//builtin.gotypeerrorinterface{Error()string}实现error接口//errors.gopackageerrorstypeerrorStrings......
  • Golang结构体方法和接收者
    结构体方法和接收者在go语言中,没有累的概念,但是可以给类型(结构体,自定义类型)定义方法。所谓方法就是定义了接收者的函数。接收者的概念就类似于其它语言中的this或者self。......
  • python调用golang 从指定序列中找出一组与目标值最接近的子序列 kayb
    python调用golang从指定序列中找出一组与目标值最接近的子序列编写go代码生成so库python代码调用编写go代码写入hello.go文件packagemainimport( "C" "en......
  • golang操作文件或者目录
    使用golang操作文件和目录Go&Rust......
  • golang echo group 用法的微妙注意点
    用不好的话,可能会引发很诡异的问题。packagemainimport( "net/http" "github.com/labstack/echo/v4" "github.com/labstack/echo/v4/middleware" "github.com/si......
  • Golang GRPC 添加header
    GolangGRPC添加header创建grpc连接时添加header使用自建的metadata添加的headr信息:key:my-headervalue:"test01"funcmain(){conn,err:=grpc.Dial("......
  • golang - go文件编码
    必须为utf-8格式win系统一般默认CRLF模式但是如果在linux系统会不支持CRLF模式因此最好使用LF,两个环境都兼容,这样就不会头疼了,不然需要单独转一下 ......
  • golang - win10 下载、安装、运行首个go文件
    1.下载运行环境官网地址https://golang.google.cn/dl/ 可以直接下载msi文件夹,双击后会自动安装环境,但作为一个程序员,但是,这种傻瓜式的安装容易带来风险,习惯性的喜......