# How to check if an imported name is used in a module?

**URL:** <https://discourse.julialang.org/t/how-to-check-if-an-imported-name-is-used-in-a-module/90400>\
**Category:** General Usage\
**Tags:** question\
**Created:** [November 17, 2022, 2:13pm UTC](https://discourse.julialang.org/t/how-to-check-if-an-imported-name-is-used-in-a-module/90400 "2022-11-17T14:13:45Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jishnub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jishnub/32/33620_2.png) [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Post date:** [November 17, 2022, 2:13pm UTC](https://discourse.julialang.org/t/how-to-check-if-an-imported-name-is-used-in-a-module/90400/1 "2022-11-17T14:13:45Z")

</div>

I want to check if all the names being imported in a module are being used somewhere, and return a list of names that aren’t being used in the module. The simple way to do this is to grep for every name, but I was wondering if someone has automated this.

E.g. in the following case

```julia
julia> module A
           f(x) = x
           g(x) = x^2
       end

julia> module B
          import Main.A: f, g
          h(x) = f(x)
       end

```

I want the search on `B` to return `g`.

A naive solution that I thought of, assuming that I have the list of imported names available, is

```julia
function count_names(v)
	@assert isdir("src")
	count = zeros(Int, length(v))
	for (root, dirs, files) in walkdir("src")
		for fname in files
			f = joinpath(root, fname)
			open(f, "r") do io
				for line in eachline(io)
					for (ind, name) in enumerate(v)
						if occursin(name, line)
							count[ind] += 1
						end
					end
				end
			end
		end
	end
	v[count .== 1]
end

```
