Skip to content

Commit 5f1096c

Browse files
authored
add goprintffuncname linter (#850)
1 parent 40d7bcd commit 5f1096c

File tree

8 files changed

+108
-0
lines changed

8 files changed

+108
-0
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ gofmt: Gofmt checks whether code was gofmt-ed. By default this tool runs with -s
221221
goimports: Goimports does everything that gofmt does. Additionally it checks unused imports [fast: true, auto-fix: true]
222222
golint: Golint differs from gofmt. Gofmt reformats Go source code, whereas golint prints out style mistakes [fast: true, auto-fix: false]
223223
gomnd: An analyzer to detect magic numbers. [fast: true, auto-fix: false]
224+
goprintffuncname: Checks that printf-like functions are named with `f` at the end [fast: true, auto-fix: false]
224225
gosec (gas): Inspects source code for security problems [fast: true, auto-fix: false]
225226
interfacer: Linter that suggests narrower interface types [fast: true, auto-fix: false]
226227
lll: Reports long lines [fast: true, auto-fix: false]
@@ -485,6 +486,7 @@ golangci-lint help linters
485486
- [whitespace](https://github.com/ultraware/whitespace) - Tool for detection of leading and trailing whitespace
486487
- [wsl](https://github.com/bombsimon/wsl) - Whitespace Linter - Forces you to use empty lines!
487488
- [gomnd](https://github.com/tommy-muehle/go-mnd) - An analyzer to detect magic numbers.
489+
- [goprintffuncname](https://github.com/jirfag/go-printf-func-name) - Checks that printf-like functions are named with `f` at the end
488490
489491
## Configuration
490492
@@ -1232,6 +1234,7 @@ Thanks to developers and authors of used linters:
12321234
- [matoous](https://github.com/matoous)
12331235
- [ultraware](https://github.com/ultraware)
12341236
- [bombsimon](https://github.com/bombsimon)
1237+
- [jirfag](https://github.com/jirfag)
12351238
- [tommy-muehle](https://github.com/tommy-muehle)
12361239
12371240
## Changelog

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ require (
2323
github.com/golangci/prealloc v0.0.0-20180630174525-215b22d4de21
2424
github.com/golangci/revgrep v0.0.0-20180526074752-d9c87f5ffaf0
2525
github.com/golangci/unconvert v0.0.0-20180507085042-28b1c447d1f4
26+
github.com/jirfag/go-printf-func-name v0.0.0-20191110105641-45db9963cdd3
2627
github.com/jingyugao/rowserrcheck v0.0.0-20191204022205-72ab7603b68a
2728
github.com/matoous/godox v0.0.0-20190911065817-5d6d842e92eb // v1.0
2829
github.com/mattn/go-colorable v0.1.4

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
130130
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
131131
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
132132
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
133+
github.com/jirfag/go-printf-func-name v0.0.0-20191110105641-45db9963cdd3 h1:jNYPNLe3d8smommaoQlK7LOA5ESyUJJ+Wf79ZtA7Vp4=
134+
github.com/jirfag/go-printf-func-name v0.0.0-20191110105641-45db9963cdd3/go.mod h1:HEWGJkRDzjJY2sqdDwxccsGicWEf9BQOZsq2tV+xzM0=
133135
github.com/jingyugao/rowserrcheck v0.0.0-20191204022205-72ab7603b68a h1:GmsqmapfzSJkm28dhRoHz2tLRbJmqhU86IPgBtN3mmk=
134136
github.com/jingyugao/rowserrcheck v0.0.0-20191204022205-72ab7603b68a/go.mod h1:xRskid8CManxVta/ALEhJha/pweKBaVG6fWgc0yH25s=
135137
github.com/jmoiron/sqlx v1.2.1-0.20190826204134-d7d95172beb5 h1:lrdPtrORjGv1HbbEvKWDUAy97mPpFm4B8hp77tcCUJY=

pkg/golinters/goprintffuncname.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package golinters
2+
3+
import (
4+
"github.com/jirfag/go-printf-func-name/pkg/analyzer"
5+
"golang.org/x/tools/go/analysis"
6+
7+
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
8+
)
9+
10+
func NewGoPrintfFuncName() *goanalysis.Linter {
11+
return goanalysis.NewLinter(
12+
"goprintffuncname",
13+
"Checks that printf-like functions are named with `f` at the end",
14+
[]*analysis.Analyzer{analyzer.Analyzer},
15+
nil,
16+
).WithLoadMode(goanalysis.LoadModeSyntax)
17+
}

pkg/lint/lintersdb/manager.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,9 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
241241
linter.NewConfig(golinters.NewWSL()).
242242
WithPresets(linter.PresetStyle).
243243
WithURL("https://github.com/bombsimon/wsl"),
244+
linter.NewConfig(golinters.NewGoPrintfFuncName()).
245+
WithPresets(linter.PresetStyle).
246+
WithURL("https://github.com/jirfag/go-printf-func-name"),
244247
linter.NewConfig(golinters.NewGoMND()).
245248
WithPresets(linter.PresetStyle).
246249
WithURL("https://github.com/tommy-muehle/go-mnd"),

test/testdata/goprintffuncname.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//args: -Egoprintffuncname
2+
package testdata
3+
4+
func PrintfLikeFuncWithBadName(format string, args ...interface{}) { // ERROR "printf-like formatting function 'PrintfLikeFuncWithBadName' should be named 'PrintfLikeFuncWithBadNamef'"
5+
}

vendor/github.com/jirfag/go-printf-func-name/pkg/analyzer/analyzer.go

Lines changed: 74 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/modules.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ github.com/hashicorp/hcl/json/scanner
9999
github.com/hashicorp/hcl/json/token
100100
# github.com/inconshreveable/mousetrap v1.0.0
101101
github.com/inconshreveable/mousetrap
102+
# github.com/jirfag/go-printf-func-name v0.0.0-20191110105641-45db9963cdd3
103+
github.com/jirfag/go-printf-func-name/pkg/analyzer
102104
# github.com/jingyugao/rowserrcheck v0.0.0-20191204022205-72ab7603b68a
103105
github.com/jingyugao/rowserrcheck/passes/rowserr
104106
# github.com/kisielk/gotool v1.0.0
@@ -194,6 +196,7 @@ golang.org/x/sys/windows
194196
golang.org/x/text/transform
195197
golang.org/x/text/unicode/norm
196198
golang.org/x/text/width
199+
# golang.org/x/tools v0.0.0-20191108193012-7d206e10da11 => github.com/golangci/tools v0.0.0-20190915081525-6aa350649b1c
197200
# golang.org/x/tools v0.0.0-20200102140908-9497f49d5709 => github.com/golangci/tools v0.0.0-20190915081525-6aa350649b1c
198201
golang.org/x/tools/go/analysis
199202
golang.org/x/tools/go/analysis/passes/asmdecl

0 commit comments

Comments
 (0)