Reorganize code into individual tool files

This commit is contained in:
Ian Gulliver
2025-06-27 21:22:36 -07:00
parent 7f6613e2df
commit c1ba594c2b
31 changed files with 2734 additions and 2580 deletions

51
tool_find_deprecated.go Normal file
View File

@@ -0,0 +1,51 @@
package main
import (
"go/ast"
"go/token"
"strings"
)
// Deprecated usage types
type DeprecatedInfo struct {
File string `json:"file"`
Usage []DeprecatedUsage `json:"usage"`
}
type DeprecatedUsage struct {
Item string `json:"item"`
Alternative string `json:"alternative,omitempty"`
Reason string `json:"reason,omitempty"`
Position Position `json:"position"`
}
func findDeprecated(dir string) ([]DeprecatedInfo, error) {
var deprecated []DeprecatedInfo
err := walkGoFiles(dir, func(path string, src []byte, file *ast.File, fset *token.FileSet) error {
info := DeprecatedInfo{
File: path,
}
// Look for deprecated comments
for _, cg := range file.Comments {
for _, c := range cg.List {
if strings.Contains(strings.ToLower(c.Text), "deprecated") {
pos := fset.Position(c.Pos())
info.Usage = append(info.Usage, DeprecatedUsage{
Item: "deprecated_comment",
Reason: c.Text,
Position: newPosition(pos),
})
}
}
}
if len(info.Usage) > 0 {
deprecated = append(deprecated, info)
}
return nil
})
return deprecated, err
}