borkdude / carve Goto Github PK
View Code? Open in Web Editor NEWRemove unused Clojure vars
License: Eclipse Public License 1.0
Remove unused Clojure vars
License: Eclipse Public License 1.0
In a similar vein to clj-kondo/clj-kondo#226, Carve could offer a clojure API.
Checking out
Lines 64 to 80 in f499f65
println
WDYT?
Thanks - V
A common issue when carving unused code is that there can be quite a few unused requires leftover that will break everything.
I was wondering if it was possible to carve them out as well, or potentially use another tool to delete all the unused imports before carving?
When running carve inside a limited network, it would be easier if there were binaries published automatically as it's done for clj-kondo.
The only way to make it work locally right now has been to clone carve locally and all it's dependencies, and use :local/root
in my deps.edn to point to all the various deps.
This kind of works for dev but could be a bit painful to configure in the internal CI tool, any chance there could be binaries built with graalvm?
I ran the command clojure -A:carve --opts '{:paths ["src" "test" "dev"] :interactive? false :aggressive? true}'
on one of my projects (and tried on a few other projects as well), but I get lots of false positives, many more things get deleted.
This is an example where the function deleted is just used straight after:
I noticed a require/:refer that results in no :refer
(empty vector) don't get discarded even with :aggressive true
. for instance this require with an unused match
symbol
(ns company.core
(:require
[clojure.set :as set]
[clojure.core.match :refer [match]]))
results in this
(ns company.core
(:require
[clojure.set :as set]
[clojure.core.match :refer []]))
expectation would be
(ns company.core
(:require
[clojure.set :as set]))
Also it would be good to add the type of warning.
Might be good to leave clojurescript def/defns which are annotated with ^:export
Ref
https://clojurescript.org/reference/advanced-compilation#access-from-javascript
It can be useful when introducing carve (maybe after a first initial pass) to create a .carve/ignore file with all the things that should indeed be ignored automatically.
Atm I've just done transforming the :text report into the .carve/ignore report which was just a couple of lines in clojure, but maybe we could just add another report format so something like this would work:
carve --opts '{:paths [...] :report {:format :ignore}}' > .carve/ignore
I can do a PR if you like the idea @borkdude ?
Hi Michiel! Thank you for a great tool! Just wondering if you would welcome a PR with yet another option resulting in Carve deleting a file in case there is no form in it other than the ns
form in the result of vars carving. My use case results in exactly this situation for several namespaces, and it's quite tedious to write myo script for this sake. WDYT?
Emacs understands output on the form
path/to/file.clj:161:32
where 161
is the line number and 32
is the column number (which can be elided.
If carve could output this format, then carve could be run from within emacs (from eshell
or something) and it could use the output to jump to the next unused symbol
I was investigating using this on the Metabase codebase, but got this error / stack trace.
carve --opts '{:paths ["src" "test"] :report {:format :text}}'
$ carve --opts '{:paths ["src" "test"] :report {:format :text}}'
WARNING: file clojure/pprint.clj not found while loading hook
WARNING: error while trying to read hook for metabase.models.setting/defsetting: Could not find namespace: clojure.pprint.
Exception in thread "main" java.lang.NullPointerException
at clojure.core$namespace.invokeStatic(core.clj:1605)
at clojure.core$namespace.invoke(core.clj:1599)
at carve.impl$ignore_QMARK_.invokeStatic(impl.clj:183)
at carve.impl$ignore_QMARK_.invoke(impl.clj:176)
at carve.impl$do_run_BANG_$fn__18981.invoke(impl.clj:260)
at clojure.core$complement$fn__5687.invoke(core.clj:1443)
at clojure.core$filter$fn__5912.invoke(core.clj:2825)
at clojure.lang.LazySeq.sval(LazySeq.java:42)
at clojure.lang.LazySeq.seq(LazySeq.java:51)
at clojure.lang.RT.seq(RT.java:535)
at clojure.core$seq__5420.invokeStatic(core.clj:139)
at clojure.core$map$fn__5885.invoke(core.clj:2750)
at clojure.lang.LazySeq.sval(LazySeq.java:42)
at clojure.lang.LazySeq.seq(LazySeq.java:51)
at clojure.lang.Cons.next(Cons.java:39)
at clojure.lang.RT.next(RT.java:713)
at clojure.core$next__5404.invokeStatic(core.clj:64)
at clojure.core$reduce1.invokeStatic(core.clj:946)
at clojure.core$set.invokeStatic(core.clj:4101)
at clojure.core$set.invoke(core.clj:4093)
at carve.impl$do_run_BANG_.invokeStatic(impl.clj:262)
at carve.impl$do_run_BANG_.invoke(impl.clj:222)
at carve.impl$run_PLUS_.invokeStatic(impl.clj:344)
at carve.impl$run_PLUS_.invoke(impl.clj:337)
at carve.api$carve_BANG_.invokeStatic(api.clj:36)
at carve.api$carve_BANG_.invoke(api.clj:25)
at carve.main$main.invokeStatic(main.clj:12)
at carve.main$main.doInvoke(main.clj:7)
at clojure.lang.RestFn.applyTo(RestFn.java:137)
at clojure.core$apply.invokeStatic(core.clj:667)
at clojure.core$apply.invoke(core.clj:662)
at carve.main$_main.invokeStatic(main.clj:16)
at carve.main$_main.doInvoke(main.clj:14)
at clojure.lang.RestFn.applyTo(RestFn.java:137)
at carve.main.main(Unknown Source)
Functions that only call themselves and are not used by other functions should be listed as unused.
We (mis)use the component library in our system. This leads to a lot of defrecords
which carve reports as being unused. It would be nice to have some way of having carve ignore the unused defrecords
. Either by brute force ignore all defrecords, or maybe carve could know about the component-library?
Assuming someone has decent test coverage, it would be cool to semi automate the whole carving process, and one way would to:
.carveignore
I guess tests should be fast enough, but I think this would really help the initial carving on bigger projects.
What do you think @borkdude ?
I have a clj-kondo configuration in a project with something like
:lint-as {bla-bla clojure.core/def...
but if I run carve all the bla-bla
� do not get ignored.
So I tried to add also bla-bla
the :exclude
list and it's still same problem.
I then thought it was not reading the .clj-kondo/config.edn file and just pasted the whole thing in the clj-kondo/config
keyword in .carve/config.edn, but it still didn't work.
Is the clj-kondo config maybe not being passed through?
From the code it looks like it should work so maybe something else is going on.
I think report might not be working on the latest commit.
If I run with report, nothing is. But on interactive mode I see three unused vars:
filipesilva@Filipes-Air ~/w/athens (lein-to-clj)> clojure -M:carve --opts '{:paths ["src" "test"] :report {:format :text}}'
filipesilva@Filipes-Air ~/w/athens (lein-to-clj)> clojure -M:carve --opts '{:paths ["src" "test"]}'
Carving src/cljc/athens/common/logging.cljc
Found unused var:
------------------
1: (ns athens.common.logging
2: "Athens logging for both clj & cljs."
3: #?(:clj
4: (:require
5: [clojure.tools.logging :as log :refer [error]])))
^--- unused var
6:
7:
8: #?(:clj (defmacro error
9: [& args]
10: `(log/error ~@args))
------------------
Type Y to remove.
Carving test/athens/db_test.cljs
Found unused var:
------------------
1: (ns athens.db-test
2: (:require
3: [athens.db :as db]
4: [clojure.pprint :refer [pprint]]
^--- unused var
5: [clojure.test :refer [deftest is are]]
6: [datascript.core :as d]))
7:
8:
9: (enable-console-print!)
------------------
Type Y to remove.
Carving test/athens/parser/impl_test.clj
Found unused var:
------------------
1: (ns athens.parser.impl-test
2: (:require
3: [athens.parser.impl :as sut]
4: [clojure.test :as t :refer [deftest is are testing]]))
^--- unused var
5:
6:
7: (defmacro parses-to
8: [parser & tests]
9: `(t/are [in# out#] (= out# (do
------------------
Type Y to remove.
filipesilva@Filipes-Air ~/w/athens (lein-to-clj)>
I'm using deps.edn with the following alias config:
{:extra-deps
{borkdude/carve
{:git/url "https://github.com/borkdude/carve"
:sha "c9a4dec89032f2003cc439c473fcd3c41e809669"}}
:main-opts ["-m" "carve.main"]}
If for example I have a config.edn file with :paths ["src" "test"]
, and I pass options from CLI
:paths ["src"]
because I only want to see src now, the config from cli is not respected and still use :paths ["src" "test"]
.
Other options get applied correctly instead, so it's quite confusing until you see how the code behaves, where collections are always merged.
IMHO it would be simpler and clearer to just ignore the default config file if you pass arguments from the CLI, since I would guess if you run it locally your really want to have certain options passed in.
If I run tests with clojure -A:test
they work fine, but if I run them in the REPL with Cider I get
1 non-passing tests:
Fail in text-report-test
expected: "test-resources/app/api.clj:3:1 api/private-lib-function\ntest-resources/app/app.clj:4:1 app/unused-function\ntest-resources/app/app.clj:5:1 app/another-unused-function"
actual: "({:filename \"test-resources/app/app.clj\",\n :row 4,\n :col 1,\n :ns app,\n :name unused-function,\n :fixed-arities #{0}}\n {:filename \"test-resources/app/app.clj\",\n :row 5,\n :col 1,\n :ns app,\n :name another-unused-function,\n :fixed-arities #{0}}\n {:filename \"test-resources/app/api.clj\",\n :row 5,\n :col 1,\n :ns api,\n :name public-lib-function,\n :fixed-arities #{0}}\n {:filename \"test-resources/app/api.clj\",\n :row 3,\n :col 1,\n :ns api,\n :name private-lib-function,\n :private true,\n :fixed-arities #{0}})\ntest-resources/app/api.clj:3:1 api/private-lib-function\ntest-resources/app/app.clj:4:1 app/unused-function\ntest-resources/app/app.clj:5:1 app/another-unused-function"
diff: - "test-resources/app/api.clj:3:1 api/private-lib-function\ntest-resources/app/app.clj:4:1 app/unused-function\ntest-resources/app/app.clj:5:1 app/another-unused-function"
+ "({:filename \"test-resources/app/app.clj\",\n :row 4,\n :col 1,\n :ns app,\n :name unused-function,\n :fixed-arities #{0}}\n {:filename \"test-resources/app/app.clj\",\n :row 5,\n :col 1,\n :ns app,\n :name another-unused-function,\n :fixed-arities #{0}}\n {:filename \"test-resources/app/api.clj\",\n :row 5,\n :col 1,\n :ns api,\n :name public-lib-function,\n :fixed-arities #{0}}\n {:filename \"test-resources/app/api.clj\",\n :row 3,\n :col 1,\n :ns api,\n :name private-lib-function,\n :private true,\n :fixed-arities #{0}})\ntest-resources/app/api.clj:3:1 api/private-lib-function\ntest-resources/app/app.clj:4:1 app/unused-function\ntest-resources/app/app.clj:5:1 app/another-unused-function"
```
Would be nice to give a bit more feedback in case someone makes a silly mistake like
clojure -A:carve --opts '{:paths [src]}'
instead of doing:
clojure -A:carve --opts '{:paths ["src"]}'
At the moment it just runs without doing anything but also without giving any error.
I think in general if you don't pass any existing path (apart from the missing ") we should give an error since that's probably not what you wanted to do?
Currently, no information is output when an exception is thrown when analyzing a file. It would be great if a try/catch block was put around impl.clj
line 145 that outputs the name of the file/line that was being analyzed when the exception was thrown. The stacktrace listed below doesn't contain this info, which makes it difficult to determine why carve threw an exception.
$ ~/Downloads/carve --opts '{:paths ["src/cljs/"]}'
Exception in thread "main" java.lang.AssertionError: Assert failed: (string-of? s r/linebreak?)
at rewrite_cljc.node.whitespace$newline_node.invokeStatic(whitespace.cljc:92)
at rewrite_cljc.node.whitespace$newline_node.invoke(whitespace.cljc:92)
at rewrite_cljc.parser.whitespace$parse_whitespace.invokeStatic(whitespace.cljc:11)
at rewrite_cljc.parser.whitespace$parse_whitespace.invoke(whitespace.cljc:5)
at rewrite_cljc.parser.core$fn__14229.invokeStatic(core.cljc:83)
at rewrite_cljc.parser.core$fn__14229.invoke(core.cljc:81)
at clojure.lang.MultiFn.invoke(MultiFn.java:229)
at rewrite_cljc.reader$read_with_meta.invokeStatic(reader.cljc:136)
at rewrite_cljc.reader$read_with_meta.invoke(reader.cljc:132)
at rewrite_cljc.parser.core$parse_next.invokeStatic(core.cljc:33)
at rewrite_cljc.parser.core$parse_next.invoke(core.cljc:31)
at rewrite_cljc.parser.core$parse_delim$fn__14213.invoke(core.cljc:41)
at rewrite_cljc.reader$read_repeatedly$fn__13624.invoke(reader.cljc:145)
at clojure.core$repeatedly$fn__6480.invoke(core.clj:5138)
at clojure.lang.LazySeq.sval(LazySeq.java:42)
at clojure.lang.LazySeq.seq(LazySeq.java:51)
at clojure.lang.RT.seq(RT.java:535)
at clojure.core$seq__5420.invokeStatic(core.clj:139)
at clojure.core$take_while$fn__5936.invoke(core.clj:2908)
at clojure.lang.LazySeq.sval(LazySeq.java:42)
at clojure.lang.LazySeq.seq(LazySeq.java:51)
at clojure.lang.Cons.next(Cons.java:39)
at clojure.lang.RT.next(RT.java:713)
at clojure.core$next__5404.invokeStatic(core.clj:64)
at clojure.core$dorun.invokeStatic(core.clj:3130)
at clojure.core$doall.invokeStatic(core.clj:3136)
at clojure.core$doall.invoke(core.clj:3136)
at rewrite_cljc.reader$read_repeatedly.invokeStatic(reader.cljc:147)
at rewrite_cljc.reader$read_repeatedly.invoke(reader.cljc:141)
at rewrite_cljc.parser.core$parse_delim.invokeStatic(core.cljc:42)
at rewrite_cljc.parser.core$parse_delim.invoke(core.cljc:37)
at rewrite_cljc.parser.core$fn__14258.invokeStatic(core.cljc:184)
at rewrite_cljc.parser.core$fn__14258.invoke(core.cljc:182)
at clojure.lang.MultiFn.invoke(MultiFn.java:229)
at rewrite_cljc.reader$read_with_meta.invokeStatic(reader.cljc:136)
at rewrite_cljc.reader$read_with_meta.invoke(reader.cljc:132)
at rewrite_cljc.parser.core$parse_next.invokeStatic(core.cljc:33)
at rewrite_cljc.parser.core$parse_next.invoke(core.cljc:31)
at rewrite_cljc.parser.core$parse_delim$fn__14213.invoke(core.cljc:41)
at rewrite_cljc.reader$read_repeatedly$fn__13624.invoke(reader.cljc:145)
at clojure.core$repeatedly$fn__6480.invoke(core.clj:5138)
at clojure.lang.LazySeq.sval(LazySeq.java:42)
at clojure.lang.LazySeq.seq(LazySeq.java:51)
at clojure.lang.RT.seq(RT.java:535)
at clojure.core$seq__5420.invokeStatic(core.clj:139)
at clojure.core$take_while$fn__5936.invoke(core.clj:2908)
at clojure.lang.LazySeq.sval(LazySeq.java:42)
at clojure.lang.LazySeq.seq(LazySeq.java:51)
at clojure.lang.Cons.next(Cons.java:39)
at clojure.lang.RT.next(RT.java:713)
at clojure.core$next__5404.invokeStatic(core.clj:64)
at clojure.core$dorun.invokeStatic(core.clj:3130)
at clojure.core$doall.invokeStatic(core.clj:3136)
at clojure.core$doall.invoke(core.clj:3136)
at rewrite_cljc.reader$read_repeatedly.invokeStatic(reader.cljc:147)
at rewrite_cljc.reader$read_repeatedly.invoke(reader.cljc:141)
at rewrite_cljc.parser.core$parse_delim.invokeStatic(core.cljc:42)
at rewrite_cljc.parser.core$parse_delim.invoke(core.cljc:37)
at rewrite_cljc.parser.core$fn__14256.invokeStatic(core.cljc:180)
at rewrite_cljc.parser.core$fn__14256.invoke(core.cljc:178)
at clojure.lang.MultiFn.invoke(MultiFn.java:229)
at rewrite_cljc.reader$read_with_meta.invokeStatic(reader.cljc:136)
at rewrite_cljc.reader$read_with_meta.invoke(reader.cljc:132)
at rewrite_cljc.parser.core$parse_next.invokeStatic(core.cljc:33)
at rewrite_cljc.parser.core$parse_next.invoke(core.cljc:31)
at rewrite_cljc.parser.core$parse_delim$fn__14213.invoke(core.cljc:41)
at rewrite_cljc.reader$read_repeatedly$fn__13624.invoke(reader.cljc:145)
at clojure.core$repeatedly$fn__6480.invoke(core.clj:5138)
at clojure.lang.LazySeq.sval(LazySeq.java:42)
at clojure.lang.LazySeq.seq(LazySeq.java:51)
at clojure.lang.RT.seq(RT.java:535)
at clojure.core$seq__5420.invokeStatic(core.clj:139)
at clojure.core$take_while$fn__5936.invoke(core.clj:2908)
at clojure.lang.LazySeq.sval(LazySeq.java:42)
at clojure.lang.LazySeq.seq(LazySeq.java:51)
at clojure.lang.Cons.next(Cons.java:39)
at clojure.lang.RT.next(RT.java:713)
at clojure.core$next__5404.invokeStatic(core.clj:64)
at clojure.core$dorun.invokeStatic(core.clj:3130)
at clojure.core$doall.invokeStatic(core.clj:3136)
at clojure.core$doall.invoke(core.clj:3136)
at rewrite_cljc.reader$read_repeatedly.invokeStatic(reader.cljc:147)
at rewrite_cljc.reader$read_repeatedly.invoke(reader.cljc:141)
at rewrite_cljc.parser.core$parse_delim.invokeStatic(core.cljc:42)
at rewrite_cljc.parser.core$parse_delim.invoke(core.cljc:37)
at rewrite_cljc.parser.core$fn__14256.invokeStatic(core.cljc:180)
at rewrite_cljc.parser.core$fn__14256.invoke(core.cljc:178)
at clojure.lang.MultiFn.invoke(MultiFn.java:229)
at rewrite_cljc.reader$read_with_meta.invokeStatic(reader.cljc:136)
at rewrite_cljc.reader$read_with_meta.invoke(reader.cljc:132)
at rewrite_cljc.parser.core$parse_next.invokeStatic(core.cljc:33)
at rewrite_cljc.parser.core$parse_next.invoke(core.cljc:31)
at rewrite_cljc.parser.core$parse_delim$fn__14213.invoke(core.cljc:41)
at rewrite_cljc.reader$read_repeatedly$fn__13624.invoke(reader.cljc:145)
at clojure.core$repeatedly$fn__6480.invoke(core.clj:5138)
at clojure.lang.LazySeq.sval(LazySeq.java:42)
at clojure.lang.LazySeq.seq(LazySeq.java:51)
at clojure.lang.RT.seq(RT.java:535)
at clojure.core$seq__5420.invokeStatic(core.clj:139)
at clojure.core$take_while$fn__5936.invoke(core.clj:2908)
at clojure.lang.LazySeq.sval(LazySeq.java:42)
at clojure.lang.LazySeq.seq(LazySeq.java:51)
at clojure.lang.Cons.next(Cons.java:39)
at clojure.lang.RT.next(RT.java:713)
at clojure.core$next__5404.invokeStatic(core.clj:64)
at clojure.core$dorun.invokeStatic(core.clj:3130)
at clojure.core$doall.invokeStatic(core.clj:3136)
at clojure.core$doall.invoke(core.clj:3136)
at rewrite_cljc.reader$read_repeatedly.invokeStatic(reader.cljc:147)
at rewrite_cljc.reader$read_repeatedly.invoke(reader.cljc:141)
at rewrite_cljc.parser.core$parse_delim.invokeStatic(core.cljc:42)
at rewrite_cljc.parser.core$parse_delim.invoke(core.cljc:37)
at rewrite_cljc.parser.core$fn__14256.invokeStatic(core.cljc:180)
at rewrite_cljc.parser.core$fn__14256.invoke(core.cljc:178)
at clojure.lang.MultiFn.invoke(MultiFn.java:229)
at rewrite_cljc.reader$read_with_meta.invokeStatic(reader.cljc:136)
at rewrite_cljc.reader$read_with_meta.invoke(reader.cljc:132)
at rewrite_cljc.parser.core$parse_next.invokeStatic(core.cljc:33)
at rewrite_cljc.parser.core$parse_next.invoke(core.cljc:31)
at rewrite_cljc.parser.core$parse_delim$fn__14213.invoke(core.cljc:41)
at rewrite_cljc.reader$read_repeatedly$fn__13624.invoke(reader.cljc:145)
at clojure.core$repeatedly$fn__6480.invoke(core.clj:5138)
at clojure.lang.LazySeq.sval(LazySeq.java:42)
at clojure.lang.LazySeq.seq(LazySeq.java:51)
at clojure.lang.RT.seq(RT.java:535)
at clojure.core$seq__5420.invokeStatic(core.clj:139)
at clojure.core$take_while$fn__5936.invoke(core.clj:2908)
at clojure.lang.LazySeq.sval(LazySeq.java:42)
at clojure.lang.LazySeq.seq(LazySeq.java:51)
at clojure.lang.Cons.next(Cons.java:39)
at clojure.lang.RT.next(RT.java:713)
at clojure.core$next__5404.invokeStatic(core.clj:64)
at clojure.core$dorun.invokeStatic(core.clj:3130)
at clojure.core$doall.invokeStatic(core.clj:3136)
at clojure.core$doall.invoke(core.clj:3136)
at rewrite_cljc.reader$read_repeatedly.invokeStatic(reader.cljc:147)
at rewrite_cljc.reader$read_repeatedly.invoke(reader.cljc:141)
at rewrite_cljc.parser.core$parse_delim.invokeStatic(core.cljc:42)
at rewrite_cljc.parser.core$parse_delim.invoke(core.cljc:37)
at rewrite_cljc.parser.core$fn__14254.invokeStatic(core.cljc:176)
at rewrite_cljc.parser.core$fn__14254.invoke(core.cljc:174)
at clojure.lang.MultiFn.invoke(MultiFn.java:229)
at rewrite_cljc.reader$read_with_meta.invokeStatic(reader.cljc:136)
at rewrite_cljc.reader$read_with_meta.invoke(reader.cljc:132)
at rewrite_cljc.parser.core$parse_next.invokeStatic(core.cljc:33)
at rewrite_cljc.parser.core$parse_next.invoke(core.cljc:31)
at rewrite_cljc.parser.core$parse_delim$fn__14213.invoke(core.cljc:41)
at rewrite_cljc.reader$read_repeatedly$fn__13624.invoke(reader.cljc:145)
at clojure.core$repeatedly$fn__6480.invoke(core.clj:5138)
at clojure.lang.LazySeq.sval(LazySeq.java:42)
at clojure.lang.LazySeq.seq(LazySeq.java:51)
at clojure.lang.RT.seq(RT.java:535)
at clojure.core$seq__5420.invokeStatic(core.clj:139)
at clojure.core$take_while$fn__5936.invoke(core.clj:2908)
at clojure.lang.LazySeq.sval(LazySeq.java:42)
at clojure.lang.LazySeq.seq(LazySeq.java:51)
at clojure.lang.Cons.next(Cons.java:39)
at clojure.lang.RT.next(RT.java:713)
at clojure.core$next__5404.invokeStatic(core.clj:64)
at clojure.core$dorun.invokeStatic(core.clj:3130)
at clojure.core$doall.invokeStatic(core.clj:3136)
at clojure.core$doall.invoke(core.clj:3136)
at rewrite_cljc.reader$read_repeatedly.invokeStatic(reader.cljc:147)
at rewrite_cljc.reader$read_repeatedly.invoke(reader.cljc:141)
at rewrite_cljc.parser.core$parse_delim.invokeStatic(core.cljc:42)
at rewrite_cljc.parser.core$parse_delim.invoke(core.cljc:37)
at rewrite_cljc.parser.core$fn__14254.invokeStatic(core.cljc:176)
at rewrite_cljc.parser.core$fn__14254.invoke(core.cljc:174)
at clojure.lang.MultiFn.invoke(MultiFn.java:229)
at rewrite_cljc.reader$read_with_meta.invokeStatic(reader.cljc:136)
at rewrite_cljc.reader$read_with_meta.invoke(reader.cljc:132)
at rewrite_cljc.parser.core$parse_next.invokeStatic(core.cljc:33)
at rewrite_cljc.parser.core$parse_next.invoke(core.cljc:31)
at rewrite_cljc.parser$parse.invokeStatic(parser.cljc:16)
at rewrite_cljc.parser$parse.invoke(parser.cljc:13)
at rewrite_cljc.parser$parse_all$fn__14263.invoke(parser.cljc:21)
at clojure.core$repeatedly$fn__6480.invoke(core.clj:5138)
at clojure.lang.LazySeq.sval(LazySeq.java:42)
at clojure.lang.LazySeq.seq(LazySeq.java:51)
at clojure.lang.RT.seq(RT.java:535)
at clojure.core$seq__5420.invokeStatic(core.clj:139)
at clojure.core$take_while$fn__5936.invoke(core.clj:2908)
at clojure.lang.LazySeq.sval(LazySeq.java:42)
at clojure.lang.LazySeq.seq(LazySeq.java:51)
at clojure.lang.Cons.next(Cons.java:39)
at clojure.lang.RT.next(RT.java:713)
at clojure.core$next__5404.invokeStatic(core.clj:64)
at clojure.core$dorun.invokeStatic(core.clj:3130)
at clojure.core$doall.invokeStatic(core.clj:3136)
at clojure.core$doall.invoke(core.clj:3136)
at rewrite_cljc.parser$parse_all.invokeStatic(parser.cljc:23)
at rewrite_cljc.parser$parse_all.invoke(parser.cljc:18)
at rewrite_cljc.parser$parse_file_all.invokeStatic(parser.cljc:54)
at rewrite_cljc.parser$parse_file_all.invoke(parser.cljc:49)
at rewrite_cljc.zip.base$of_file.invokeStatic(base.cljc:89)
at rewrite_cljc.zip.base$of_file.invoke(base.cljc:80)
at rewrite_cljc.zip.base$of_file.invokeStatic(base.cljc:87)
at rewrite_cljc.zip.base$of_file.invoke(base.cljc:80)
at carve.impl$carve_BANG_.invokeStatic(impl.clj:145)
at carve.impl$carve_BANG_.invoke(impl.clj:142)
at carve.impl$run_BANG_.invokeStatic(impl.clj:258)
at carve.impl$run_BANG_.invoke(impl.clj:210)
at carve.main$main.invokeStatic(main.clj:77)
at carve.main$main.doInvoke(main.clj:64)
at clojure.lang.RestFn.applyTo(RestFn.java:137)
at clojure.core$apply.invokeStatic(core.clj:667)
at clojure.core$apply.invoke(core.clj:662)
at carve.main$_main.invokeStatic(main.clj:84)
at carve.main$_main.doInvoke(main.clj:82)
at clojure.lang.RestFn.applyTo(RestFn.java:137)
at carve.main.main(Unknown Source)
Approach, inspired by deps-infer: https://github.com/borkdude/deps-infer
1 Which namespaces are required in paths
2 Lint libraries one by one from deps.edn so we know which namespaces belong to which libraries
3 If there are libraries of which no namespace was used, report them as unused (and/or interactively remove)
/cc @lread Perhaps this seems like a fun issue to look into, no pressure though!
I noticed that if you kill the process while you are doing a "carving session" all the changes you already accepted are not rolled back.
I guess there are pros and cons and with everything under revision control it should not matter so much, but maybe it should at least ask if you want to keep the changes or revert them?
When I pass many flags to carve, it gets a bit tricky to keep track of all the quotes and ().
Maybe if there was a flag --opts-from
I could more simply have all the configuration in an end file and get read them from there?
-main
at the moment are always marked for deletion, would be good to ignore them by default since probably you don't want to delete them.
This function refers to itself and isn't carved away if unused:
(defn least
"Return the least argument (as defined by the compare function) in O(n) time."
{:arglists '([& xs])}
([] nil)
([a] a)
([a b] (if (neg? (compare a b)) a b))
([a b & more] (reduce least (least a b) more)))
It's because of the last clause.
How about a mode which adds a ^:deprecated for unused def/defns instead of deleting them.
Just a thought. I don't have a good general use case to justify.
This might be hard to implement, but I noticed that if you have a namespace like this
(:import (org.apache.kafka.streams.processor TimestampExtractor))
(:gen-class
:implements [org.apache.kafka.streams.processor.TimestampExtractor]))
(defn -extract [_ record previous]
(do-something))
-extract
would be deleted, even if it's actually used, and its definition has the side effect of implementing that interface.
We can look at all the namespace declarations and their files. Then put all the files in the right order. Then run carve on it.
Also see:
$ clojure -e "(binding [clojure.core/*loading-verbosely* true] (require '[babashka.main]))" | grep clojure.core/load
Took a moment to realize that simply typing "y" (lowercase) and hitting enter doesn't remove the code.
sample file for repro
core_test.clj.zip
yields only 7 lines after carve process. expectation is to preserve the newline in the file and thus get an empty line at line 8
@borkdude carve is a nice tool. we'd like to integrate it in CICD pipelines so it provides automatic fixes eventually
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.