NoahTheDuke / splint

A Clojure linter focused on style and code shape.

Home Page:https://cljdoc.org/d/io.github.noahtheduke/splint/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to run with custom rules?

p1tt1 opened this issue · comments

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

Is it possible to fork without splint?

commented

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.

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"
commented

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

commented

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.

commented

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.

commented

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