cljfmt icon indicating copy to clipboard operation
cljfmt copied to clipboard

Include project.clj by default for lein plugin

Open jacobemcken opened this issue 2 years ago • 4 comments

Since the file project.clj is specific to Leiningen projects it seem like a good default.

Resolves: #279

jacobemcken avatar Dec 10 '22 20:12 jacobemcken

Thanks for the PR!

Why did you choose concat over cons here?

Also, can you change the commit message to:

Update Lein plugin to always include project.clj

Fixes #279.

I think the "by default" is misleading, because in this case it can't be changed. If this turns out to be an issue, we can add in an option to allow it to be omitted.

Have you tested to ensure that this plugin change works with both check and fix?

weavejester avatar Dec 14 '22 17:12 weavejester

Why did you choose concat over cons here?

My lack of knowledge.

I think the "by default" is misleading, because in this case it can't be changed.

Either I don't understand meaning of your comment or I disagree. As soon as you provide an alternative configuration in the project.clj file, like:

...
    :cljfmt {:paths ["src"]}
...

The project.clj file is no longer include. What do you mean by "it can't be changed"?

I had only tested with check initially, but now I have also successfully tested it with fix :+1: Thanks for the reminder.

jacobemcken avatar Dec 29 '22 13:12 jacobemcken

As soon as you provide an alternative configuration in the project.clj file, like:

...
    :cljfmt {:paths ["src"]}
...

The project.clj file is no longer include

I don't think this is correct:

leiningen.cljfmt=> (format-paths {:source-paths ["src"], :test-paths ["test"], :cljfmt {:paths ["src"]}})
("project.clj" #object[java.io.File 0x2ac11170 "src"])

You cons the string "project.clj" onto the list regardless of what is set in :paths. You've also put the string in the wrong place, as its not checked to see whether it exists (a small possibility, but a possibility), and it's not converted into a file instance.

weavejester avatar Jan 18 '23 02:01 weavejester

... and it's not converted into a file instance.

The reason why it worked as a string regardless, is that both check and fix parses the list of "paths" through find-files which applies io/file again: https://github.com/weavejester/cljfmt/blob/a4dd48ec94e9345b51eca13a086c91cef61a1fcd/cljfmt/src/cljfmt/main.clj#L33-L34

Thankfully, layering io/file on itself like (io/file (io/file "some_file.txt")) just returns a file object #object[java.io.File 0x2ac11170 "some_file.txt"].

I've moved "extending paths with the project file" earlier, which also required changing how the filter works. An alternative would be to only check for (.exists %). Is this what you had in mind?

jacobemcken avatar Jan 18 '23 12:01 jacobemcken