2016-05-12 06:24:42 +03:00
|
|
|
# Unused [![Build Status](https://travis-ci.org/joshuaclayton/unused.svg?branch=master)](https://travis-ci.org/joshuaclayton/unused)
|
2016-04-28 12:37:06 +03:00
|
|
|
|
2016-05-12 13:37:30 +03:00
|
|
|
A command line tool to identify unused code.
|
2016-04-28 12:37:06 +03:00
|
|
|
|
2016-05-27 13:10:50 +03:00
|
|
|
![Image of Unused Output](http://i.giphy.com/3o7qDT1I4OfQxnJTvW.gif)
|
2016-05-11 00:24:28 +03:00
|
|
|
|
2016-05-12 13:37:30 +03:00
|
|
|
## "What kinds of projects can I used it on?"
|
|
|
|
|
|
|
|
Anything.
|
|
|
|
|
|
|
|
Yes, literally anything.
|
|
|
|
|
2016-05-23 12:02:54 +03:00
|
|
|
It's probably best if you have a ctags file it can read from (it looks in
|
|
|
|
`.git`, `tmp`, and the root directory for a `tags` file), but if you have
|
|
|
|
another way to pipe a bunch of methods/functions/classes/modules/whatever in,
|
|
|
|
that works too.
|
2016-05-12 13:37:30 +03:00
|
|
|
|
|
|
|
Right now, there are some special cases built in for Rails and Phoenix apps
|
|
|
|
(specifically, assumptions about what's fine to only have one reference to,
|
|
|
|
e.g. Controllers in Rails and Views in Phoenix), but it'll work on Rubygems,
|
|
|
|
Elixir packages, or anything else.
|
|
|
|
|
|
|
|
That said, be confident the code you're removing won't break your program.
|
|
|
|
Especially with projects built in Ruby, Elixir, or JavaScript, there are ways
|
|
|
|
to dynamically trigger or define behavior that may be surprising. A test suite
|
|
|
|
can help here, but still cannot determine every possible execution path.
|
|
|
|
|
2016-05-12 05:29:29 +03:00
|
|
|
## Installing
|
|
|
|
|
2016-05-12 13:40:29 +03:00
|
|
|
### Homebrew (Recommended)
|
2016-05-12 05:29:29 +03:00
|
|
|
|
|
|
|
You can install [my formulae] via [Homebrew] with `brew tap`:
|
|
|
|
|
|
|
|
```sh
|
|
|
|
brew tap joshuaclayton/formulae
|
|
|
|
```
|
|
|
|
|
|
|
|
Next, run:
|
|
|
|
|
|
|
|
```sh
|
|
|
|
brew install unused
|
|
|
|
```
|
|
|
|
|
|
|
|
[my formulae]: https://github.com/joshuaclayton/homebrew-formulae
|
|
|
|
[Homebrew]: http://brew.sh/
|
|
|
|
|
|
|
|
Alternatively, you can install by hand.
|
|
|
|
|
2016-05-12 13:40:29 +03:00
|
|
|
### Installing by hand
|
2016-05-12 05:29:29 +03:00
|
|
|
|
|
|
|
This project uses [Haskell] and [Stack].
|
|
|
|
|
|
|
|
Once you have these tools installed:
|
|
|
|
|
|
|
|
```sh
|
|
|
|
stack setup
|
|
|
|
stack install
|
|
|
|
```
|
|
|
|
|
|
|
|
This will generate a binary in `$HOME/.local/bin`; ensure this directory is in
|
|
|
|
your `$PATH`.
|
|
|
|
|
|
|
|
[Haskell]: https://www.haskell.org
|
|
|
|
[Stack]: http://www.haskellstack.org
|
|
|
|
|
2016-04-29 12:55:09 +03:00
|
|
|
## Using Unused
|
|
|
|
|
2016-05-21 17:20:25 +03:00
|
|
|
`unused` attempts to read from common tags file locations (`.git/tags`,
|
|
|
|
`tags`, and `tmp/tags`).
|
2016-04-29 12:55:09 +03:00
|
|
|
|
2016-05-21 17:20:25 +03:00
|
|
|
In an application where the tags file exists, run:
|
2016-04-29 12:55:09 +03:00
|
|
|
|
|
|
|
```sh
|
2016-05-21 17:20:25 +03:00
|
|
|
unused
|
2016-04-29 12:55:09 +03:00
|
|
|
```
|
|
|
|
|
2016-05-21 17:20:25 +03:00
|
|
|
If you want to specify a custom tags file, or load tokens from somewhere else,
|
|
|
|
run:
|
|
|
|
|
|
|
|
```sh
|
|
|
|
cat .custom/tags | unused --stdin
|
|
|
|
```
|
|
|
|
|
|
|
|
To view more usage options, run:
|
|
|
|
|
|
|
|
```sh
|
|
|
|
unused --help
|
|
|
|
```
|
2016-04-29 12:55:09 +03:00
|
|
|
|
2016-05-11 18:15:18 +03:00
|
|
|
## Requirements
|
|
|
|
|
|
|
|
Unused leverages [Ag](https://github.com/ggreer/the_silver_searcher) to
|
|
|
|
analyze the codebase; as such, you'll need to have `ag` available in your
|
2016-05-12 05:29:29 +03:00
|
|
|
`$PATH`. This is set as an explicit dependency in Homebrew.
|
2016-04-29 12:55:09 +03:00
|
|
|
|
2016-05-11 04:03:56 +03:00
|
|
|
## Testing
|
|
|
|
|
|
|
|
To run the test suite, run:
|
|
|
|
|
|
|
|
```sh
|
|
|
|
stack test
|
|
|
|
```
|
|
|
|
|
2016-04-28 12:37:06 +03:00
|
|
|
## License
|
|
|
|
|
|
|
|
Copyright 2016 Josh Clayton. See the [LICENSE](LICENSE).
|