@@ -22,7 +22,7 @@ func (a *analyzer) reportCallExpr(pass *analysis.Pass, ce *ast.CallExpr, fnInfo
22
22
23
23
switch fun := ce .Fun .(type ) {
24
24
case * ast.SelectorExpr :
25
- if fun .Sel .Name != createTempName {
25
+ if fun .Sel == nil || fun . Sel .Name != createTempName {
26
26
return false
27
27
}
28
28
@@ -31,15 +31,13 @@ func (a *analyzer) reportCallExpr(pass *analysis.Pass, ce *ast.CallExpr, fnInfo
31
31
return false
32
32
}
33
33
34
- if expr .Name == osPkgName {
35
- if isFirstArgEmptyString (ce ) {
36
- pass .Reportf (ce .Pos (),
37
- `%s.%s("", ...) could be replaced by %[1]s.%[2]s(%s.%s(), ...) in %s` ,
38
- osPkgName , createTempName , fnInfo .ArgName , tempDirName , fnInfo .Name ,
39
- )
34
+ if expr .Name == osPkgName && isFirstArgEmptyString (ce ) {
35
+ pass .Reportf (ce .Pos (),
36
+ `%s.%s("", ...) could be replaced by %[1]s.%[2]s(%s.%s(), ...) in %s` ,
37
+ osPkgName , createTempName , fnInfo .ArgName , tempDirName , fnInfo .Name ,
38
+ )
40
39
41
- return true
42
- }
40
+ return true
43
41
}
44
42
45
43
case * ast.Ident :
@@ -49,49 +47,47 @@ func (a *analyzer) reportCallExpr(pass *analysis.Pass, ce *ast.CallExpr, fnInfo
49
47
50
48
pkgName := getPkgNameFromType (pass , fun )
51
49
52
- if pkgName == osPkgName {
53
- if isFirstArgEmptyString (ce ) {
54
- pass .Reportf (ce .Pos (),
55
- `%s.%s("", ...) could be replaced by %[1]s.%[2]s(%s.%s(), ...) in %s` ,
56
- osPkgName , createTempName , fnInfo .ArgName , tempDirName , fnInfo .Name ,
57
- )
50
+ if pkgName == osPkgName && isFirstArgEmptyString (ce ) {
51
+ pass .Reportf (ce .Pos (),
52
+ `%s.%s("", ...) could be replaced by %[1]s.%[2]s(%s.%s(), ...) in %s` ,
53
+ osPkgName , createTempName , fnInfo .ArgName , tempDirName , fnInfo .Name ,
54
+ )
58
55
59
- return true
60
- }
56
+ return true
61
57
}
62
58
}
63
59
64
60
return false
65
61
}
66
62
67
- func (a * analyzer ) reportSelector (pass * analysis.Pass , sel * ast.SelectorExpr , fnInfo * FuncInfo ) {
68
- expr , ok := sel .X .(* ast.Ident )
69
- if ! ok {
63
+ func (a * analyzer ) reportSelector (pass * analysis.Pass , se * ast.SelectorExpr , fnInfo * FuncInfo ) {
64
+ if se .Sel == nil || ! se .Sel .IsExported () {
70
65
return
71
66
}
72
67
73
- if ! sel .Sel .IsExported () {
68
+ ident , ok := se .X .(* ast.Ident )
69
+ if ! ok {
74
70
return
75
71
}
76
72
77
- a .report (pass , sel .Pos (), expr .Name , sel .Sel .Name , fnInfo )
73
+ a .report (pass , se .Pos (), ident .Name , se .Sel .Name , fnInfo )
78
74
}
79
75
80
- func (a * analyzer ) reportIdent (pass * analysis.Pass , expr * ast.Ident , fnInfo * FuncInfo ) {
81
- if ! slices . Contains ( a . fieldNames , expr . Name ) {
76
+ func (a * analyzer ) reportIdent (pass * analysis.Pass , ident * ast.Ident , fnInfo * FuncInfo ) {
77
+ if ! ident . IsExported ( ) {
82
78
return
83
79
}
84
80
85
- if ! expr . IsExported ( ) {
81
+ if ! slices . Contains ( a . fieldNames , ident . Name ) {
86
82
return
87
83
}
88
84
89
- pkgName := getPkgNameFromType (pass , expr )
85
+ pkgName := getPkgNameFromType (pass , ident )
90
86
91
- a .report (pass , expr .Pos (), pkgName , expr .Name , fnInfo )
87
+ a .report (pass , ident .Pos (), pkgName , ident .Name , fnInfo )
92
88
}
93
89
94
- //nolint:gocyclo // The complexity is expected by the cases to check.
90
+ //nolint:gocyclo // The complexity is expected by the number of cases to check.
95
91
func (a * analyzer ) report (pass * analysis.Pass , pos token.Pos , origPkgName , origName string , fnInfo * FuncInfo ) {
96
92
switch {
97
93
case a .osMkdirTemp && origPkgName == osPkgName && origName == mkdirTempName :
@@ -131,8 +127,8 @@ func isFirstArgEmptyString(ce *ast.CallExpr) bool {
131
127
return bl .Kind == token .STRING && bl .Value == `""`
132
128
}
133
129
134
- func getPkgNameFromType (pass * analysis.Pass , expr * ast.Ident ) string {
135
- o := pass .TypesInfo .ObjectOf (expr )
130
+ func getPkgNameFromType (pass * analysis.Pass , ident * ast.Ident ) string {
131
+ o := pass .TypesInfo .ObjectOf (ident )
136
132
137
133
if o == nil || o .Pkg () == nil {
138
134
return ""
0 commit comments