forked from golangci/golangci-lint
-
Notifications
You must be signed in to change notification settings - Fork 1
/
util.go
41 lines (33 loc) · 959 Bytes
/
util.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package golinters
import (
"fmt"
"path/filepath"
"strings"
"golang.org/x/tools/go/analysis"
"github.com/golangci/golangci-lint/pkg/config"
)
func formatCode(code string, _ *config.Config) string {
if strings.Contains(code, "`") {
return code // TODO: properly escape or remove
}
return fmt.Sprintf("`%s`", code)
}
func formatCodeBlock(code string, _ *config.Config) string {
if strings.Contains(code, "`") {
return code // TODO: properly escape or remove
}
return fmt.Sprintf("```\n%s\n```", code)
}
func getFileNames(pass *analysis.Pass) []string {
var fileNames []string
for _, f := range pass.Files {
fileName := pass.Fset.PositionFor(f.Pos(), true).Filename
ext := filepath.Ext(fileName)
if ext != "" && ext != ".go" {
// position has been adjusted to a non-go file, revert to original file
fileName = pass.Fset.PositionFor(f.Pos(), false).Filename
}
fileNames = append(fileNames, fileName)
}
return fileNames
}