Skip to content

Commit 02ebaf5

Browse files
committed
add goprintffuncname linter
1 parent 1248f09 commit 02ebaf5

File tree

8 files changed

+109
-2
lines changed

8 files changed

+109
-2
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ godox: Tool for detection of FIXME, TODO and other comment keywords [fast: true,
219219
gofmt: Gofmt checks whether code was gofmt-ed. By default this tool runs with -s option to check for code simplification [fast: true, auto-fix: true]
220220
goimports: Goimports does everything that gofmt does. Additionally it checks unused imports [fast: true, auto-fix: true]
221221
golint: Golint differs from gofmt. Gofmt reformats Go source code, whereas golint prints out style mistakes [fast: true, auto-fix: false]
222+
goprintffuncname: Checks that printf-like functions are named with `f` at the end [fast: true, auto-fix: false]
222223
gosec (gas): Inspects source code for security problems [fast: true, auto-fix: false]
223224
interfacer: Linter that suggests narrower interface types [fast: true, auto-fix: false]
224225
lll: Reports long lines [fast: true, auto-fix: false]
@@ -480,6 +481,7 @@ golangci-lint help linters
480481
- [funlen](https://github.com/ultraware/funlen) - Tool for detection of long functions
481482
- [whitespace](https://github.com/ultraware/whitespace) - Tool for detection of leading and trailing whitespace
482483
- [wsl](https://github.com/bombsimon/wsl) - Whitespace Linter - Forces you to use empty lines!
484+
- [goprintffuncname](https://github.com/jirfag/go-printf-func-name) - Checks that printf-like functions are named with `f` at the end
483485
484486
## Configuration
485487
@@ -1163,6 +1165,7 @@ Thanks to developers and authors of used linters:
11631165
- [matoous](https://github.com/matoous)
11641166
- [ultraware](https://github.com/ultraware)
11651167
- [bombsimon](https://github.com/bombsimon)
1168+
- [jirfag](https://github.com/jirfag)
11661169
11671170
## Changelog
11681171

go.mod

Lines changed: 2 additions & 1 deletion
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/matoous/godox v0.0.0-20190911065817-5d6d842e92eb // v1.0
2728
github.com/mattn/go-colorable v0.1.4
2829
github.com/mitchellh/go-homedir v1.1.0
@@ -41,7 +42,7 @@ require (
4142
github.com/ultraware/whitespace v0.0.4
4243
github.com/uudashr/gocognit v0.0.0-20190926065955-1655d0de0517
4344
github.com/valyala/quicktemplate v1.2.0
44-
golang.org/x/tools v0.0.0-20191010075000-0337d82405ff
45+
golang.org/x/tools v0.0.0-20191108193012-7d206e10da11
4546
gopkg.in/yaml.v2 v2.2.4
4647
honnef.co/go/tools v0.0.1-2019.2.3
4748
mvdan.cc/interfacer v0.0.0-20180901003855-c20040233aed

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
124124
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
125125
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
126126
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
127+
github.com/jirfag/go-printf-func-name v0.0.0-20191110105641-45db9963cdd3 h1:jNYPNLe3d8smommaoQlK7LOA5ESyUJJ+Wf79ZtA7Vp4=
128+
github.com/jirfag/go-printf-func-name v0.0.0-20191110105641-45db9963cdd3/go.mod h1:HEWGJkRDzjJY2sqdDwxccsGicWEf9BQOZsq2tV+xzM0=
127129
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
128130
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
129131
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=

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
@@ -208,6 +208,9 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
208208
linter.NewConfig(golinters.NewWSL()).
209209
WithPresets(linter.PresetStyle).
210210
WithURL("https://github.com/bombsimon/wsl"),
211+
linter.NewConfig(golinters.NewGoPrintfFuncName()).
212+
WithPresets(linter.PresetStyle).
213+
WithURL("https://github.com/jirfag/go-printf-func-name"),
211214
}
212215

213216
isLocalRun := os.Getenv("GOLANGCI_COM_RUN") == ""

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 & 1 deletion
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/kisielk/gotool v1.0.0
103105
github.com/kisielk/gotool
104106
github.com/kisielk/gotool/internal/load
@@ -187,7 +189,7 @@ golang.org/x/sys/windows
187189
golang.org/x/text/transform
188190
golang.org/x/text/unicode/norm
189191
golang.org/x/text/width
190-
# golang.org/x/tools v0.0.0-20191010075000-0337d82405ff => github.com/golangci/tools v0.0.0-20190915081525-6aa350649b1c
192+
# golang.org/x/tools v0.0.0-20191108193012-7d206e10da11 => github.com/golangci/tools v0.0.0-20190915081525-6aa350649b1c
191193
golang.org/x/tools/go/analysis
192194
golang.org/x/tools/go/analysis/passes/asmdecl
193195
golang.org/x/tools/go/analysis/passes/assign

0 commit comments

Comments
 (0)