NoahTheDuke / splint

A Clojure linter focused on style and code shape.
https://cljdoc.org/d/io.github.noahtheduke/splint/
Mozilla Public License 2.0
116 stars 2 forks source link

How to run with custom rules? #8

Closed p1tt1 closed 6 months ago

p1tt1 commented 9 months ago

I ask what is the best way to start splint with inflow defined rules?

Is it possible to fork without splint?

NoahTheDuke commented 8 months ago

What do you mean, "inflow defined rules"? If you mean custom rules, then there's a small amount of work, which I hope to smooth soon.

First, define the rules in some namespace (dev.rules for example). Next, add it to your .splint.edn file: p1tt1/special-rule {:enabled true}. Then call clojure -M:splint -e '(require 'dev.rules)'. This will load the file and then execute the splint runner as normal, including your rule.

I am not entirely sure if you can do this with the bbin version, I haven't tried yet.

Let me know if you need help.

p1tt1 commented 8 months ago

Oh sry, I mean "custom" rules.

Thanks for the quick answer!. -e "(require 'dev.rules)" is sadly an unknown operation:

❯ clj -M:splint -e "(require 'dev.rules)"
splint errors:
Unknown option: "-e"
NoahTheDuke commented 8 months ago

Ah damn, I thought that would work. Let me see if I can whip something up to help you out.

NoahTheDuke commented 8 months ago

Ah, I missed the crucial final bit. There are two ways to handle it.

1) You add the -e call directly to the :main-opts in your alias: :splint {:extra-paths ["<PATH TO DEV RULES>"] :extra-deps {io.github.noahtheduke/splint {:mvn/version "1.10.1"}} :main-opts ["-e" "(require 'dev.rules)" "-m" "noahtheduke.splint"]}.

2) Instead of specifying a :main-opts in the alias, you write the main arg -m noahtheduke.splint explicitly. Your :splint alias is: :splint {:extra-paths ["<PATH TO DEV RULES>"] :extra-deps {io.github.noahtheduke/splint {:mvn/version "1.10.1"}}} and the invocation is clojure -M:splint -e "(require 'dev.rules)" -m noahtheduke.splint.

I'll update the docs while I consider how best to handle this automatically.

NoahTheDuke commented 6 months ago

Okay, having thought about this for a little while, I have a solution in mind. I'd like your feedback before I begin implementation.

There will be a new command-line flag -r / --require as well as a require top-level entry in .splint.edn. This must be a vector of files. All of the provided .clj files will be loaded with clojure.core/load-file (and therefore the paths must be relative to the calling site) before running the primary linting step.

This shouldn't be too hard to implement, so please let me know if that would suit your needs.

NoahTheDuke commented 6 months ago

I decided to implement it as described. Will be released shortly. Thanks!