Skip to content

Commit

Permalink
chore: new module name
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez committed Oct 19, 2024
1 parent 7558a9e commit 3fd6db1
Show file tree
Hide file tree
Showing 10 changed files with 229 additions and 16 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: golangci-lint
on:
push:
branches:
- main
- master
pull_request:

permissions:
contents: read

env:
GOLANGCI_LINT_VERSION: v1.60
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 }}
36 changes: 36 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.idea/
/go-printf-func-name
108 changes: 108 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -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
Expand Down
15 changes: 15 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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 ./...
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'
```
9 changes: 7 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
module github.com/jirfag/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
)
17 changes: 8 additions & 9 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
8 changes: 4 additions & 4 deletions pkg/analyzer/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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 {
Expand Down

0 comments on commit 3fd6db1

Please sign in to comment.