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,14 +76,13 @@ 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 {
|
||||
for _, comment := range fnDecl.Doc.List {
|
||||
if !strings.Contains(comment.Text, "go:redirect-from") {
|
||||
continue
|
||||
}
|
||||
@ -97,7 +96,7 @@ func findRedirects(goFiles []string) ([]*redirect, error) {
|
||||
|
||||
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)
|
||||
return nil, fmt.Errorf("malformed go:redirect-from syntax for %q\n-> %q", fqName, comment.Text)
|
||||
}
|
||||
|
||||
redirects = append(redirects, &redirect{
|
||||
@ -107,7 +106,6 @@ func findRedirects(goFiles []string) ([]*redirect, error) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return redirects, nil
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user