tolitius / boot-check

check, analyze and inspect Clojure/Script code
Eclipse Public License 1.0
70 stars 9 forks source link

any way for yagni to ignore test files? #10

Open ags799 opened 6 years ago

ags799 commented 6 years ago

Hi, really enjoying boot-check, thanks! Yagni is giving me some trouble though. It's failing because of my test functions, which will of course lack any references.

It seems that I can get Yagni to accept these test functions by adding them to its entry-points option. This works, but it doesn't seem too nice: as my repository grows, I'll have many tests and this entry-points list will become quite large.

I have tried

(deftask yagni []
  (set-env! :source-paths #{"src"})
  (tolitius.boot-check/with-yagni "-t" :options {:entry-points ["my.package/-main"]}))

I thought that would work, since my test files are in test/ not src/.

Unfortunately it made no difference: Yagni still reported the tests unreferenced and threw an error.

Would appreciate any advice to resolve this situation. Thanks so much.

tolitius commented 6 years ago

It's failing because of my test functions

do you mean Yagni does not look at your test functions?

The way (I understand) Yagni works it receives root(s) and builds the graph of vars that are navigatable from these root(s), hence if you do not provide root(s) Yagni would only find nodes that are traversable from ":main".

Try to ask Yagni directly, its author might have some ideas, since boot-check mostly delegates all the work to it.

ags799 commented 6 years ago

Thanks, made an issue on Yagni: https://github.com/venantius/yagni/issues/38

And regarding your question, Yagni does look at my test functions, and it reports them as unused. It throws an error because these test functions are unused. Such an error is a red herring: test functions would never be accessible from a program's entrypoint, and never should be.

venantius commented 5 years ago

As I commented on venantius/yagni#38 - this is an issue that should be resolved here rather than within Yagni itself. The Yagni interface for running the checker takes a list of files and the assumption for Yagni the plugin was that files under test/ should be omitted.

Boot-check seems to be passing test/* files in as part of the fileset arg to tolitius.checker.yagni/check. This can be easily resolved here by either omitting or filtering such files before passing them to Yagni.

tolitius commented 5 years ago

I don't think boot-check passes test/* unless test is in the classpath (i.e. set-env!) when it is run.

for example, running this from the boot-check's root (-v allows you to see the debug logs):

[boot-check]$ boot -v check/with-yagni

will show:

yagni is about to look at: -- 
[".../tolitius/checker/eastwood.clj"
 ".../tolitius/checker/kibit.clj"
 ".../tolitius/core/reporting.clj"
 ".../tolitius/checker/bikeshed.clj"
 ".../tolitius/core/check.clj"
 ".../tolitius/checker/yagni.clj"
 ".../tolitius/boot/helper.clj"
 ".../tolitius/reporter/html.clj"
 ".../tolitius/boot_check.clj"]
 --

whereas:

[boot-check]$ boot -v test-yagni

will include the test files

yagni is about to look at: -- 
[".../tolitius/checker/bikeshed.clj"
 ".../tolitius/boot/helper.clj"
 ".../tolitius/checker/eastwood.clj"
 ".../tolitius/core/check.clj"
 ".../tolitius/reporter/html.clj"
 ".../tolitius/checker/yagni.clj"
 ".../tolitius/core/reporting.clj"
 ".../tolitius/boot_check.clj"
 ".../tolitius/checker/kibit.clj"
 ".../test/with_eastwood.clj"
 ".../test/with_yagni.clj"
 ".../test/with_kibit.clj"]
--

the reason is that the test-yagni task adds "test" in the environment before calling check/with-yagni.

@ags799 can you check whether you add "test" in the environment you run check/with-yagni in?