@@ -25,47 +25,45 @@ var Analyzer = &analysis.Analyzer{
2525}
2626
2727func run (pass * analysis.Pass ) (any , error ) {
28- insp , err := astutil .Inspector (pass )
28+ root , err := astutil .Root (pass )
2929 if err != nil {
3030 return nil , err
3131 }
3232 noLintLinesByFile := nolint .BuildLineIndex (pass , "sortslice" )
3333
34- nodeFilter := []ast.Node {(* ast .CallExpr )(nil )}
35-
36- insp .Preorder (nodeFilter , func (n ast.Node ) {
37- call , ok := n .(* ast.CallExpr )
34+ for cur := range root .Preorder ((* ast .CallExpr )(nil )) {
35+ call , ok := cur .Node ().(* ast.CallExpr )
3836 if ! ok {
39- return
37+ continue
4038 }
4139
4240 pos := pass .Fset .PositionFor (call .Pos (), false )
4341 if filecheck .IsTestFile (pos .Filename ) {
44- return
42+ continue
4543 }
4644 if nolint .HasDirective (pos , noLintLinesByFile ) {
47- return
45+ continue
4846 }
4947
5048 sel , ok := call .Fun .(* ast.SelectorExpr )
5149 if ! ok {
52- return
50+ continue
5351 }
5452 pkgIdent , ok := sel .X .(* ast.Ident )
5553 if ! ok {
56- return
54+ continue
5755 }
5856 if pass .TypesInfo == nil {
59- return
57+ continue
6058 }
6159 obj := pass .TypesInfo .ObjectOf (pkgIdent )
6260 // ObjectOf can be nil when type information is incomplete.
6361 if obj == nil {
64- return
62+ continue
6563 }
6664 pkgName , ok := obj .(* types.PkgName )
6765 if ! ok || pkgName .Imported ().Path () != "sort" {
68- return
66+ continue
6967 }
7068
7169 switch sel .Sel .Name {
@@ -75,7 +73,7 @@ func run(pass *analysis.Pass) (any, error) {
7573 case "SliceStable" :
7674 pass .ReportRangef (call , "sort.SliceStable is not type-safe; use slices.SortStableFunc instead" )
7775 }
78- })
76+ }
7977
8078 return nil , nil
8179}
0 commit comments