File tree Expand file tree Collapse file tree 2 files changed +16
-2
lines changed
Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -942,7 +942,7 @@ func CheckTrim(pass *analysis.Pass) (interface{}, error) {
942942 if ! ok {
943943 return false
944944 }
945- if fn , ok := call . Fun .( * ast. Ident ); ! ok || fn . Name != "len" {
945+ if ! code . IsCallTo ( pass , call , "len" ) {
946946 return false
947947 }
948948 if len (call .Args ) != 1 {
@@ -1059,7 +1059,7 @@ func CheckTrim(pass *analysis.Pass) (interface{}, error) {
10591059 if fun != "HasPrefix" {
10601060 return
10611061 }
1062- if fn , ok := index . Fun .( * ast. Ident ); ! ok || fn . Name != "len" {
1062+ if ! code . IsCallTo ( pass , index , "len" ) {
10631063 return
10641064 }
10651065 if len (index .Args ) != 1 {
Original file line number Diff line number Diff line change @@ -139,3 +139,17 @@ func fn() {
139139 println (id1 )
140140 }
141141}
142+
143+ func fn3 () {
144+ const s1 = "a string value"
145+
146+ var id1 = "a string value"
147+ len := func (string ) int { return 0 } // don't accept non-builtin definition of len
148+ if strings .HasPrefix (id1 , s1 ) {
149+ id1 = id1 [len (s1 ):]
150+ }
151+
152+ if strings .HasSuffix (id1 , s1 ) {
153+ id1 = id1 [:len (id1 )- len (s1 )]
154+ }
155+ }
You can’t perform that action at this time.
0 commit comments