Cross referencing tool for Elm - find usages and unused code
> Cross-referencing tools for Elm. Find unused code, and figure out where
> specific functions are used.
``shell`
npm i -g elm-xref
To index a project and find unused functions, execute elm-xref in the sameelm.json
directory as your . This works for both application as well as package projects.
To find usages of a function, specify the fully qualified function name as an
argument.
Examples on rtfeldman/elm-spa-example@c8c3201:
`shellTo find unused functions:
$ elm-xref
Unused functions:
- /Users/ilias/Src/elm/elm-spa-example/src/Api.elm:294:1 Api.cacheStorageKey
- /Users/ilias/Src/elm/elm-spa-example/src/Api.elm:299:1 Api.credStorageKey
- /Users/ilias/Src/elm/elm-spa-example/src/Api.elm:73:1 Api.decode
- /Users/ilias/Src/elm/elm-spa-example/src/Author.elm:120:1 Author.follow
- /Users/ilias/Src/elm/elm-spa-example/src/Author.elm:125:1 Author.unfollow
- /Users/ilias/Src/elm/elm-spa-example/src/Avatar.elm:55:1 Avatar.toMaybeString
- /Users/ilias/Src/elm/elm-spa-example/src/Email.elm:30:7 Email.Email
- /Users/ilias/Src/elm/elm-spa-example/src/Email.elm:44:1 Email.decoder
- /Users/ilias/Src/elm/elm-spa-example/src/Email.elm:39:1 Email.encode
- /Users/ilias/Src/elm/elm-spa-example/src/Email.elm:34:1 Email.toString
- /Users/ilias/Src/elm/elm-spa-example/src/Main.elm:112:7 Main.ChangedRoute
- /Users/ilias/Src/elm/elm-spa-example/src/Page.elm:26:7 Page.Login
- /Users/ilias/Src/elm/elm-spa-example/src/Page.elm:27:7 Page.Register
- /Users/ilias/Src/elm/elm-spa-example/src/Page.elm:28:7 Page.Settings
- /Users/ilias/Src/elm/elm-spa-example/src/Page/Settings.elm:90:7 Page.Settings.Valid
- /Users/ilias/Src/elm/elm-spa-example/src/Page/Settings.elm:456:1 Page.Settings.nothingIfEmpty
- /Users/ilias/Src/elm/elm-spa-example/src/Route.elm:19:7 Route.Root
:Value constructors of types are also tracked. Note that only constructing values
is tracked as usage - pattern matches and destructuring are _not_ tracked as
usage.
Usage tracking isn't terribly clever. This tool only does static analysis and
does not attempt to evaluate any expressions. As a result, functions that only
appear in "obviously unreachable code" (i.e. conditionals that always evaluate
to
False) do very much count as usage.Roadmap
- [ ] Support whitelisting (f.e. with phantom types or internal modules with consistent API)
- [ ] Show unused parameters
- [ ] Support type aliases (as function and in type signatures)
License
See the
LICENSE` file.