MCPcopy Create free account
hub / github.com/JordanCoin/codemap / NewAstGrepScanner

Function NewAstGrepScanner

scanner/astgrep.go:49–75  ·  view source on GitHub ↗

NewAstGrepScanner creates a scanner, extracting rules to temp dir

()

Source from the content-addressed store, hash-verified

47
48// NewAstGrepScanner creates a scanner, extracting rules to temp dir
49func NewAstGrepScanner() (*AstGrepScanner, error) {
50 // Find ast-grep binary (installed as "sg" via brew, "ast-grep" via cargo/pipx)
51 binary := findAstGrepBinary()
52
53 // Create temp directory for rules
54 rulesDir, err := os.MkdirTemp("", "codemap-sg-rules-*")
55 if err != nil {
56 return nil, err
57 }
58
59 // Extract embedded rules
60 entries, err := sgRules.ReadDir("sg-rules")
61 if err != nil {
62 os.RemoveAll(rulesDir)
63 return nil, err
64 }
65
66 for _, entry := range entries {
67 content, err := sgRules.ReadFile("sg-rules/" + entry.Name())
68 if err != nil {
69 continue
70 }
71 os.WriteFile(filepath.Join(rulesDir, entry.Name()), content, 0644)
72 }
73
74 return &AstGrepScanner{rulesDir: rulesDir, binary: binary}, nil
75}
76
77// extractJSONArray finds and extracts a JSON array from output that may have garbage before it
78// This handles ast-grep 0.40.2 which had a debug println! bug

Callers 4

TestBenchmarkAstGrepFunction · 0.85
TestAstGrepScannerFunction · 0.85
ScanForDepsFunction · 0.85
NewAstGrepAnalyzerFunction · 0.85

Calls 1

findAstGrepBinaryFunction · 0.85

Tested by 2

TestBenchmarkAstGrepFunction · 0.68
TestAstGrepScannerFunction · 0.68