From 705c7984305ee8391024520ab0e7eb51ba16747a Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Sat, 19 Oct 2024 15:17:27 +0200 Subject: [PATCH] chore: new module name --- .gitattributes | 3 + .github/workflows/lint.yml | 40 ++++++++++++ .github/workflows/tests.yml | 36 +++++++++++ .gitignore | 2 + .golangci.yml | 108 ++++++++++++++++++++++++++++++++ LICENSE | 1 + Makefile | 15 +++++ README.md | 9 ++- cmd/go-printf-func-name/main.go | 2 +- go.mod | 11 +++- go.sum | 17 +++-- pkg/analyzer/analyzer.go | 8 +-- pkg/analyzer/analyzer_test.go | 2 +- 13 files changed, 235 insertions(+), 19 deletions(-) create mode 100644 .gitattributes create mode 100644 .github/workflows/lint.yml create mode 100644 .github/workflows/tests.yml create mode 100644 .gitignore create mode 100644 .golangci.yml create mode 100644 Makefile diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..55f26a1 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,3 @@ +go.sum linguist-generated +* text=auto eol=lf +*.ps1 text eol=crlf diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..b9c41a3 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,40 @@ +name: golangci-lint +on: + push: + branches: + - main + - master + pull_request: + +permissions: + contents: read + +env: + GOLANGCI_LINT_VERSION: v1.61 + CGO_ENABLED: 0 + +jobs: + golangci: + strategy: + matrix: + go: [stable] + os: [ubuntu-latest, macos-latest, windows-latest] + name: lint + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version: ${{ matrix.go }} + + - name: Check and get dependencies + run: | + go mod download + go mod tidy + git diff --exit-code go.mod + git diff --exit-code go.sum + + - name: golangci-lint + uses: golangci/golangci-lint-action@v6 + with: + version: ${{ env.GOLANGCI_LINT_VERSION }} diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..1f811ee --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,36 @@ +name: Tests +on: + push: + branches: + - main + - master + pull_request: + +permissions: + contents: read + +env: + CGO_ENABLED: 0 + +jobs: + cross: + name: Go + strategy: + matrix: + go-version: [ oldstable, stable ] + os: [ubuntu-latest, macos-latest, windows-latest] + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version: ${{ matrix.go-version }} + + - name: Test + run: make test + + - name: Build + run: make build + + - name: Vet integration + run: make vet diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cb7a208 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.idea/ +/go-printf-func-name diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..789bc7e --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,108 @@ +linters: + disable-all: true + enable: + - asasalint + - asciicheck + - bidichk + - containedctx + - contextcheck +# - copyloopvar + - cyclop + - dogsled + - dupl + - dupword + - durationcheck + - err113 + - errcheck + - errname + - errorlint + - fatcontext + - forbidigo + - funlen + - gci + - gocheckcompilerdirectives + - gochecknoglobals + - gochecknoinits + - gocognit + - goconst + - gocritic + - gocyclo + - godot + - godox + - gofmt + - gofumpt + - goimports + - gomoddirectives + - gomodguard + - goprintffuncname + - gosec + - gosimple + - govet + - importas + - inamedparam + - ineffassign + - interfacebloat +# - intrange + - ireturn + - loggercheck + - maintidx + - makezero + - mirror + - misspell + - musttag + - nestif + - nilerr + - nlreturn + - noctx + - nolintlint + - nonamedreturns + - perfsprint + - predeclared + - reassign + - revive + - staticcheck + - stylecheck + - tagalign + - tagliatelle + - tenv + - testableexamples + - testifylint + - thelper + - tparallel + - unconvert + - unparam + - unused + - usestdlibvars + - wastedassign + - whitespace + - wrapcheck + - wsl + +linters-settings: + stylecheck: + checks: ['*', '-ST1000'] + cyclop: + max-complexity: 15 + +issues: + exclude-use-default: false + max-issues-per-linter: 0 + max-same-issues: 0 + exclude-rules: + - linters: + - revive + text: "package-comments: should have a package comment" + - linters: + - revive + text: "exported: .+ should have comment or be unexported" + - path: pkg/analyzer/analyzer.go + linters: + - gochecknoglobals + text: "Analyzer is a global variable" + +output: + show-stats: true + sort-results: true + sort-order: + - linter + - file diff --git a/LICENSE b/LICENSE index d06a809..4585140 100644 --- a/LICENSE +++ b/LICENSE @@ -1,5 +1,6 @@ MIT License +Copyright (c) 2024 Golangci-lint authors Copyright (c) 2020 Isaev Denis Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..991654a --- /dev/null +++ b/Makefile @@ -0,0 +1,15 @@ +.PHONY: lint test build vet + +default: lint test vet + +test: + go test -v -cover ./... + +lint: + golangci-lint run + +build: + go build ./cmd/go-printf-func-name/ + +vet: build + go vet -vettool=./go-printf-func-name ./... diff --git a/README.md b/README.md index 2d6d6d1..5618fa8 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,9 @@ The Go linter `go-printf-func-name` checks that printf-like functions are named with `f` at the end. -For example, `myLog` should be named `myLogf` by Go convention: +## Example + +`myLog` should be named `myLogf` by Go convention: ```go package main @@ -14,3 +16,8 @@ func myLog(format string, args ...interface{}) { log.Printf(prefix + format, args...) } ``` + +```console +$ go vet -vettool=$(which go-printf-func-name) ./... +./main.go:5:1: printf-like formatting function 'myLog' should be named 'myLogf' +``` diff --git a/cmd/go-printf-func-name/main.go b/cmd/go-printf-func-name/main.go index a3d4116..241b4cd 100644 --- a/cmd/go-printf-func-name/main.go +++ b/cmd/go-printf-func-name/main.go @@ -3,7 +3,7 @@ package main import ( "flag" - "github.com/jirfag/go-printf-func-name/pkg/analyzer" + "github.com/golangci/go-printf-func-name/pkg/analyzer" "golang.org/x/tools/go/analysis/singlechecker" ) diff --git a/go.mod b/go.mod index ea789e3..8e0ab8f 100644 --- a/go.mod +++ b/go.mod @@ -1,5 +1,10 @@ -module github.com/jirfag/go-printf-func-name +module github.com/golangci/go-printf-func-name -go 1.13 +go 1.22.0 -require golang.org/x/tools v0.0.0-20191108193012-7d206e10da11 +require golang.org/x/tools v0.26.0 + +require ( + golang.org/x/mod v0.21.0 // indirect + golang.org/x/sync v0.8.0 // indirect +) diff --git a/go.sum b/go.sum index fba7126..486c8d4 100644 --- a/go.sum +++ b/go.sum @@ -1,9 +1,8 @@ -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/tools v0.0.0-20191108193012-7d206e10da11 h1:Yq9t9jnGoR+dBuitxdo9l6Q7xh/zOyNnYUtDKaQ3x0E= -golang.org/x/tools v0.0.0-20191108193012-7d206e10da11/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191109212701-97ad0ed33101 h1:LCmXVkvpQCDj724eX6irUTPCJP5GelFHxqGSWL2D1R0= -golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +golang.org/x/mod v0.21.0 h1:vvrHzRwRfVKSiLrG+d4FMl/Qi4ukBCE6kZlTUkDYRT0= +golang.org/x/mod v0.21.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY= +golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= +golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/tools v0.26.0 h1:v/60pFQmzmT9ExmjDv2gGIfi3OqfKoEP6I5+umXlbnQ= +golang.org/x/tools v0.26.0/go.mod h1:TPVVj70c7JJ3WCazhD8OdXcZg/og+b9+tH/KxylGwH0= diff --git a/pkg/analyzer/analyzer.go b/pkg/analyzer/analyzer.go index 7937dd4..bce4b24 100644 --- a/pkg/analyzer/analyzer.go +++ b/pkg/analyzer/analyzer.go @@ -4,10 +4,9 @@ import ( "go/ast" "strings" + "golang.org/x/tools/go/analysis" "golang.org/x/tools/go/analysis/passes/inspect" "golang.org/x/tools/go/ast/inspector" - - "golang.org/x/tools/go/analysis" ) var Analyzer = &analysis.Analyzer{ @@ -18,12 +17,13 @@ var Analyzer = &analysis.Analyzer{ } func run(pass *analysis.Pass) (interface{}, error) { - inspector := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector) + insp := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector) + nodeFilter := []ast.Node{ (*ast.FuncDecl)(nil), } - inspector.Preorder(nodeFilter, func(node ast.Node) { + insp.Preorder(nodeFilter, func(node ast.Node) { funcDecl := node.(*ast.FuncDecl) if res := funcDecl.Type.Results; res != nil && len(res.List) != 0 { diff --git a/pkg/analyzer/analyzer_test.go b/pkg/analyzer/analyzer_test.go index d613ffe..e38ad04 100644 --- a/pkg/analyzer/analyzer_test.go +++ b/pkg/analyzer/analyzer_test.go @@ -5,7 +5,7 @@ import ( "path/filepath" "testing" - "github.com/jirfag/go-printf-func-name/pkg/analyzer" + "github.com/golangci/go-printf-func-name/pkg/analyzer" "golang.org/x/tools/go/analysis/analysistest" )