1
2
3
4
5 package analyzerutil
6
7
8
9 import (
10 "go/token"
11 "os"
12
13 "golang.org/x/tools/go/analysis"
14 )
15
16
17
18 func ReadFile(pass *analysis.Pass, filename string) ([]byte, *token.File, error) {
19 readFile := pass.ReadFile
20 if readFile == nil {
21 readFile = os.ReadFile
22 }
23 content, err := readFile(filename)
24 if err != nil {
25 return nil, nil, err
26 }
27 tf := pass.Fset.AddFile(filename, -1, len(content))
28 tf.SetLinesForContent(content)
29 return content, tf, nil
30 }
31
View as plain text