File tree Expand file tree Collapse file tree 2 files changed +15
-5
lines changed Expand file tree Collapse file tree 2 files changed +15
-5
lines changed Original file line number Diff line number Diff line change @@ -26,6 +26,10 @@ func run(pass *analysis.Pass) (interface{}, error) {
2626 inspector .Preorder (nodeFilter , func (node ast.Node ) {
2727 funcDecl := node .(* ast.FuncDecl )
2828
29+ if res := funcDecl .Type .Results ; res != nil && len (res .List ) != 0 {
30+ return
31+ }
32+
2933 params := funcDecl .Type .Params .List
3034 if len (params ) < 2 { // [0] must be format (string), [1] must be args (...interface{})
3135 return
@@ -40,6 +44,10 @@ func run(pass *analysis.Pass) (interface{}, error) {
4044 return
4145 }
4246
47+ if formatParamNames := params [len (params )- 2 ].Names ; len (formatParamNames ) == 0 || formatParamNames [len (formatParamNames )- 1 ].Name != "format" {
48+ return
49+ }
50+
4351 argsParamType , ok := params [len (params )- 1 ].Type .(* ast.Ellipsis )
4452 if ! ok { // args are not ellipsis (...args)
4553 return
Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ func printfLikeButWithStrings(format string, args ...string) {}
88
99func printfLikeButWithBadFormat (format int , args ... interface {}) {}
1010
11- func secondArgIsNotEllipsis (arg1 string , arg2 int ) {}
11+ func secondArgIsNotEllipsis (format string , arg int ) {}
1212
1313func printfLikeButWithExtraInterfaceMethods (format string , args ... interface {
1414 String () string
@@ -17,12 +17,14 @@ func printfLikeButWithExtraInterfaceMethods(format string, args ...interface {
1717
1818func prinfLikeFuncf (format string , args ... interface {}) {}
1919
20+ func prinfLikeFuncWithReturnValue (format string , args ... interface {}) string {
21+ return ""
22+ }
23+
24+ func prinfLikeFuncWithAnotherFormatArgName (msg string , args ... interface {}) {}
25+
2026func prinfLikeFunc (format string , args ... interface {}) {} // want "printf-like formatting function"
2127
2228func prinfLikeFuncWithExtraArgs1 (extraArg , format string , args ... interface {}) {} // want "printf-like formatting function"
2329
2430func prinfLikeFuncWithExtraArgs2 (extraArg int , format string , args ... interface {}) {} // want "printf-like formatting function"
25-
26- func prinfLikeFuncWithReturnValue (format string , args ... interface {}) string { // want "printf-like formatting function"
27- return ""
28- }
You can’t perform that action at this time.
0 commit comments