• Stars
    star
    218
  • Rank 175,542 (Top 4 %)
  • Language
    Clojure
  • License
    Eclipse Public Li...
  • Created about 9 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Leiningen plugin for finding dead code

Yagni

Build Status Dependency Status Clojars Project

Yagni - You Aren't Gonna Need It.

Yagni is a static code analyzer that helps you find unused code in your applications and libraries.

I've written a blog post describing Yagni in greater depth here.

Background

No matter how it happens, sooner or later an application is going to end up with unused code. It's time to call Yagni, the exterminator.

Yagni works by identifying all of the interned vars and declared Java classes in the namespaces findable within your :source-paths, and then walking the forms of those vars and declarations.

As it walks the forms, it builds a graph of references to other vars and declarations. It then searches the graph from a set of entrypoints (by default your project's :main method), and emits warnings for anything that it couldn't find in the graph's search.

Installation

Merge the following into your ~/.lein/profiles.clj:

{:user {:plugins [[venantius/yagni "0.1.7"]]}}

Usage

To have Yagni search for dead code, just run:

$ lein yagni

Usage from deps.edn

You can also use Yagni via a deps.edn alias. Merge this with your deps.edn:

{:aliases {:yagni
           {:extra-deps {venantius/yagni {:mvn/version "0.1.7"}}
            :exec-fn yagni.core/run-yagni
            :exec-args {:source-paths ["src/clj"]
                        :main your.project}}}

And then run:

$ clj -X:yagni

Configuration

Yagni works by searching your codebase from an initial set of entrypoints. By default, Yagni assumes that the only entrypoint for your project is the one listed in your project.clj's :main key. Obviously, this is only useful for applications and tools with CLI invocations.

As libraries, multi-main programs, and certain other types of projects either tend to have no :main or many entrypoint methods, you can instead enumerate a list of entrypoints for your project in a .lein-yagni file in the root directory of your project. Feel free to take a look at the one in this project as an example.

Examples

Running lein yagni on the sample project located here will emit the following output:

$ lein yagni
=================== WARNING: Parents ======================
== Could not find any references to the following vars. ===
===========================================================

secondns/func-the-second

================== WARNING: Children ======================
== The following vars have references to them, but their ==
== parents do not.                                       ==
===========================================================

secondns/notafunc

Contributing

In general, bug reports, fixes, and code cleanup are always appreciated. Feature requests are liable to be subject to a bit more discussion.

When filing issues, please include the following:

  • The operating system
  • The JDK version
  • The Leiningen version
  • The Clojure version
  • Any plugins and dependencies in your project.clj and your ~/.lein/profiles.clj

License

Copyright © 2018 W. David Jarvis

Distributed under the Eclipse Public License, the same as Clojure.

More Repositories

1

ultra

A Leiningen plugin for a superior development environment
Clojure
1,240
star
2

pyro

Light up your Clojure stacktraces
Clojure
316
star
3

accountant

ClojureScript navigation for single-page applications, made simple.
Clojure
249
star
4

glojure

The Glojure programming language
Go
172
star
5

vim-cljfmt

A Vim plugin for cljfmt, the Clojure formatting tool.
Vim Script
152
star
6

glow

Syntax highlighting for Clojure source code.
Clojure
101
star
7

vim-eastwood

A Vim plugin for Clojure's Eastwood linter
Vim Script
84
star
8

dotfiles

It's creepy that you want these
Shell
18
star
9

maze

Mazes for Programmers
Go
7
star
10

photon

Experiments in realtime web framework design. Like Meteor, but for Clojure(Script)
Clojure
7
star
11

droplet

Droplet is a Python library for sampling, sketching, and summarizing data from massive data streams.
Python
6
star
12

school

C
2
star
13

takehome

Various puzzles, homework assignments, and interview questions
Python
2
star
14

rethink

A Clojure driver for RethinkDB.
Clojure
1
star
15

yagni-test

Dummy app for testing Yagni
Clojure
1
star
16

spindle

Playing with Node.js and express. Don't take this seriously.
JavaScript
1
star
17

demo

A demo application that shows repeated 404s for a valid worker endpoint using Google App Engine push queues
Go
1
star
18

babel

Chat bots for yo' chat ops.
Clojure
1
star
19

etrade-statement-scraper

A Python script for scraping E*Trade monthly statements for data
Python
1
star
20

shrike

Hosted Code Quality for Clojure -- an abandoned CodeClimate competitor.
CSS
1
star
21

orcs-in-space

Orcs in space!!!
Haskell
1
star
22

darg

Kill the status meeting -- an abandoned IDoneThis competitor.
CSS
1
star