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

Function normalizeImport

scanner/filegraph.go:206–225  ·  view source on GitHub ↗

normalizeImport converts various import syntaxes to a path-like format

(imp string)

Source from the content-addressed store, hash-verified

204
205// normalizeImport converts various import syntaxes to a path-like format
206func normalizeImport(imp string) string {
207 // Remove quotes
208 imp = strings.Trim(imp, "\"'`")
209
210 // Python dots to slashes: app.core.config -> app/core/config
211 if strings.Contains(imp, ".") && !strings.Contains(imp, "/") && !strings.HasPrefix(imp, ".") {
212 imp = strings.ReplaceAll(imp, ".", string(filepath.Separator))
213 }
214
215 // Rust :: to slashes: crate::foo::bar -> foo/bar
216 if strings.HasPrefix(imp, "crate::") {
217 imp = strings.TrimPrefix(imp, "crate::")
218 imp = strings.ReplaceAll(imp, "::", string(filepath.Separator))
219 }
220 if strings.HasPrefix(imp, "super::") {
221 imp = strings.ReplaceAll(imp, "::", string(filepath.Separator))
222 }
223
224 return imp
225}
226
227// resolveRelative handles ./foo and ../bar style imports
228func resolveRelative(imp, fromDir string, idx *fileIndex) []string {

Callers 3

TestDepsNormalizeImportFunction · 0.85
fuzzyResolveFunction · 0.85
TestNormalizeImportFunction · 0.85

Calls

no outgoing calls

Tested by 2

TestDepsNormalizeImportFunction · 0.68
TestNormalizeImportFunction · 0.68