[ANN] Introducing Yagni, a Leiningen plugin for finding unused code

452 views
Skip to first unread message

W. David Jarvis

unread,
Jun 23, 2015, 1:39:09 PM6/23/15
to clo...@googlegroups.com
Hello everyone. 

I'm happy to announce the initial release of Yagni, a Leiningen plugin for finding unused code. 

At a high level, Yagni works by identifying all of the interned vars in the namespaces findable within your :source-paths, and then walking the forms of those vars.

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

There's some other clever stuff going on there and some options for additional customization as well. I've written up a blog post, located here, that goes into considerably more detail on how the plugin works and what the project's roadmap looks like. 

For those of you who want to look at the repository, it's on GitHub here: https://github.com/venantius/yagni

And, of course, for those of you who just want to get started fiddling, you can add the following to your project's plugins map `[venantius/yagni "0.1.1"]` and type `lein yagni` to give it a whirl.

Cheers!

 - V

Andrew Oberstar

unread,
Jun 23, 2015, 7:27:46 PM6/23/15
to clo...@googlegroups.com
Haven't tried it yet, but looks good. Nice work!

Andrew Oberstar

--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@googlegroups.com
Note that posts from new members are moderated - please be patient with your first post.
To unsubscribe from this group, send email to
clojure+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Yehonathan Sharvit

unread,
Jun 24, 2015, 4:11:01 AM6/24/15
to clo...@googlegroups.com
Does yagni work with cljs projects?

juan.facorro

unread,
Jun 24, 2015, 1:45:53 PM6/24/15
to clo...@googlegroups.com
Yehonathan Sharvit,

I think Google's Closure compiler already has dead code elimination, so it's available for ClojureScript even if Yagni doesn't provide it :).

Cheers,

Juan

Fluid Dynamics

unread,
Jun 24, 2015, 5:53:43 PM6/24/15
to clo...@googlegroups.com
 FMIIW, but I think they serve orthogonal purposes. Google Closure finds code (mostly library parts your program doesn't use) that your particular program doesn't need and omits it from the build to save disk and bandwidth. Yagni finds obsolete code that is no longer reached in your program or from *any* public entry point to your library (whether a particular program uses that entry point or not) and issues warnings, so you know that either something is maintenance deadweight or you have a bug because you *meant* to call it somewhere but forgot, or it's become accidentally shadowed or something.

juan.facorro

unread,
Jun 24, 2015, 5:58:14 PM6/24/15
to clo...@googlegroups.com
That's a good point.

W. David Jarvis

unread,
Jun 24, 2015, 6:53:45 PM6/24/15
to clo...@googlegroups.com
Indeed. I'd argue it's better not to have unused code in the codebase in the first place, regardless of what the Closure compiler does to help when it comes to compiling assets. 

I haven't tested this with cljs projects, but on the face of it I don't see why Yagni's methodology wouldn't work. If you get a chance to give it a try I'd love the feedback :)

Yehonathan Sharvit

unread,
Jun 30, 2015, 5:44:39 AM6/30/15
to clo...@googlegroups.com
Yagni ignore `cljs` files.





--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@googlegroups.com
Note that posts from new members are moderated - please be patient with your first post.
To unsubscribe from this group, send email to
clojure+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to a topic in the Google Groups "Clojure" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/clojure/fGhjG70w0_U/unsubscribe.
To unsubscribe from this group and all its topics, send an email to clojure+u...@googlegroups.com.

Stuart Halloway

unread,
Jun 30, 2015, 11:11:05 AM6/30/15
to clo...@googlegroups.com
Nice.

It would be really cool if run-yagni was a pure function of source-paths and mains.  This would make the dependency on lein optional and allow adoption on e.g. mainland Java projects.

Stu

You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure+u...@googlegroups.com.

W. David Jarvis

unread,
Jul 2, 2015, 12:32:09 AM7/2/15
to clo...@googlegroups.com
Hey Stuart - 

Could you clarify what you meant your comment? I'm not sure I understand what you mean by a pure function in this context.

 - David

============
============



Colin Fleming

unread,
Jul 2, 2015, 2:27:44 AM7/2/15
to clo...@googlegroups.com
I may be putting words in Stuart's mouth here, but what I believe he meant is that it would be great if Yagni were just a Clojure library with a function you could call passing it everything it needs (probably source paths and entry point details), and ideally returning the results as data. Then the lein plugin could just call that function and print the results, but other tooling which might not use lein could also take advantage of Yagni.

Great work BTW, Yagni looks very cool. I'm planning to implement something similar in Cursive but I'll be using the IntelliJ infrastructure to do it. The idea is the same, though.

Stuart Halloway

unread,
Jul 2, 2015, 2:02:42 PM7/2/15
to clo...@googlegroups.com
Thanks Colin, that is exactly it.

W. David Jarvis

unread,
Jul 5, 2015, 1:31:06 PM7/5/15
to clo...@googlegroups.com
Thanks for the feedback; I agree that it would be nice for Yagni to expose a functional interface for other programs. I'll add it to the to-do list :)

 - D
Reply all
Reply to author
Forward
0 new messages