예제 #1
0
// NewAutoImporter returns an AutoImporter visitor that generates patches to add missing
// import statements to the standard library.
//     auto := NewAutoImporter(patchable.File)
//     scopes.WalkFile(patchable.File, auto)
//     patchable.FprintPatched(os.Stdout, patchable.All(), auto.Patches)
func NewAutoImporter(file *ast.File) *AutoImporter {
	auto := &AutoImporter{patch.Patches{}, make(map[*ast.Ident]bool), make(map[string]bool), file.Name.End()}
	for _, imp := range file.Imports {
		auto.m[imports.GetNameOrGuess(imp)] = true
	}
	return auto
}
예제 #2
0
파일: unused.go 프로젝트: elazarl/gosloppy
func (v *Unused) ExitScope(scope *ast.Scope, node ast.Node, last bool) scopes.Visitor {
	for _, obj := range scope.Objects {
		if !v.Used[obj] {
			v.Visitor.UnusedObj(obj, node)
		}
	}
	if file, ok := node.(*ast.File); ok {
		for _, imp := range file.Imports {
			name := imports.GetNameOrGuess(imp)
			if !v.UsedImports[name] && !anonymousImport(imp.Name) && imp.Path.Value != `"C"` {
				v.Visitor.UnusedImport(imp)
			}
		}
	}
	return v
}