mirror of
https://github.com/taigrr/gopher-os
synced 2025-01-18 04:43:13 -08:00
Redirects tool should only consider comments attached to functions
This commit is contained in:
parent
336cbb415d
commit
ce34763e23
@ -76,35 +76,33 @@ func findRedirects(goFiles []string) ([]*redirect, error) {
|
||||
|
||||
cmap := ast.NewCommentMap(fset, f, f.Comments)
|
||||
cmap.Filter(f)
|
||||
for astNode, commentGroups := range cmap {
|
||||
for astNode := range cmap {
|
||||
fnDecl, ok := astNode.(*ast.FuncDecl)
|
||||
if !ok {
|
||||
if !ok || fnDecl.Doc == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, commentGroup := range commentGroups {
|
||||
for _, comment := range commentGroup.List {
|
||||
if !strings.Contains(comment.Text, "go:redirect-from") {
|
||||
continue
|
||||
}
|
||||
|
||||
// build qualified name to fn
|
||||
fqName := fmt.Sprintf("%s/%s.%s",
|
||||
prefix,
|
||||
goFile[:strings.LastIndexByte(goFile, '/')],
|
||||
fnDecl.Name,
|
||||
)
|
||||
|
||||
fields := strings.Fields(comment.Text)
|
||||
if len(fields) != 2 || fields[0] != "//go:redirect-from" {
|
||||
return nil, fmt.Errorf("malformed go:redirect-from syntax for %q", fqName)
|
||||
}
|
||||
|
||||
redirects = append(redirects, &redirect{
|
||||
src: fields[1],
|
||||
dst: fqName,
|
||||
})
|
||||
for _, comment := range fnDecl.Doc.List {
|
||||
if !strings.Contains(comment.Text, "go:redirect-from") {
|
||||
continue
|
||||
}
|
||||
|
||||
// build qualified name to fn
|
||||
fqName := fmt.Sprintf("%s/%s.%s",
|
||||
prefix,
|
||||
goFile[:strings.LastIndexByte(goFile, '/')],
|
||||
fnDecl.Name,
|
||||
)
|
||||
|
||||
fields := strings.Fields(comment.Text)
|
||||
if len(fields) != 2 || fields[0] != "//go:redirect-from" {
|
||||
return nil, fmt.Errorf("malformed go:redirect-from syntax for %q\n-> %q", fqName, comment.Text)
|
||||
}
|
||||
|
||||
redirects = append(redirects, &redirect{
|
||||
src: fields[1],
|
||||
dst: fqName,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user