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 705c798
Show file tree
Hide file tree
Showing 13 changed files with 235 additions and 19 deletions.
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
go.sum linguist-generated
* text=auto eol=lf
*.ps1 text eol=crlf
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.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 }}
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'
```
2 changes: 1 addition & 1 deletion cmd/go-printf-func-name/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
11 changes: 8 additions & 3 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
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
)
17 changes: 8 additions & 9 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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
2 changes: 1 addition & 1 deletion pkg/analyzer/analyzer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down

0 comments on commit 705c798

Please sign in to comment.