6ffb098b20
Why? ==== Dynamic languages, and Rails in particular, support some fun method creation. One common pattern is, within RSpec, to create matchers dynamically based on predicate methods. Two common examples are: * `#admin?` gets converted to the matcher `#be_admin` * `#has_active_todos?` gets converted to the matcher `#have_active_todos` This especially comes into play when writing page objects with predicate methods. This change introduces the concept of aliases, a way to describe the before/after for these transformations. This introduces a direct swap with a wildcard value (%s), although this may change in the future to support other transformations for pluralization, camel-casing, etc. Externally, aliases are not grouped together by term; however, the underlying counts are summed together, increasing the total occurrences and likely pushing the individual method out of "high" likelihood into "medium" or "low" likelihood. Closes #19. |
||
---|---|---|
app | ||
data | ||
src/Unused | ||
test | ||
.gitignore | ||
.travis.yml | ||
LICENSE | ||
NEWS | ||
README.md | ||
Setup.hs | ||
stack.yaml | ||
unused.cabal |
Unused
A command line tool to identify unused code.
"What kinds of projects can I used it on?"
Anything.
Yes, literally anything.
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.
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.
Installing
Homebrew (Recommended)
You can install my formulae via Homebrew with brew tap
:
brew tap joshuaclayton/formulae
Next, run:
brew install unused
Alternatively, you can install by hand.
Installing by hand
This project uses Haskell and Stack.
Once you have these tools installed:
stack setup
stack install
This will generate a binary in $HOME/.local/bin
; ensure this directory is in
your $PATH
.
Using Unused
unused
attempts to read from common tags file locations (.git/tags
,
tags
, and tmp/tags
).
In an application where the tags file exists, run:
unused
If you want to specify a custom tags file, or load tokens from somewhere else, run:
cat .custom/tags | unused --stdin
To view more usage options, run:
unused --help
Requirements
Unused leverages Ag to
analyze the codebase; as such, you'll need to have ag
available in your
$PATH
. This is set as an explicit dependency in Homebrew.
Testing
To run the test suite, run:
stack test
License
Copyright 2016 Josh Clayton. See the LICENSE.