Fork me on GitHub
Joshua Suskalo01:10:03

Is there an unused public var linter now? Or did lsp add that?

Joshua Suskalo01:10:29

oh yeah, it's being reported as coming from clojure-lsp


There's but its for private vars. With public vars, it's hard to know if its meant to be used by consumers of your library code or not.


@didibus If it scans your whole codebase and it's an application, it can detect that. It works really well for us at work -- although it isn't able to spot functions called from our legacy code (of course) nor functions called dynamically.


Ya, it probably relies on clj-kondo's analysis, but I'm pretty sure this issue is why there is no such linter in clj-kondo itself, though borkdude instead created: for it


Because kondo doesn't know what is your project code, it just know to lint the given files


But it doesn't have the concept of project source paths or classpath of your application


Hum, it has its cache, wouldn't that work?


That cache was built by clojure-lsp right?


Hum, kinda but not really. See the doc It's a clj-kondo feature for its linters that are cross-namespace. Clojure-lsp might conveniently setup a cache for your project for you, but you can do it even without Clojure-lsp.


I guess it could be an optional linter like some of the other slightly controversial ones


One person's "controversial" is someone else's "mainstream" 🙂


Haha, true true, but I think some of them you just know they'll be controversial, like missing docstring, or warn when shadowing a global var, or when require is not alphbetically sorted. They just have that quality of being tab vs spaces like in nature 😛


It's great that with clojure we can avoid that whole tabs vs. spaces debacle and indent our code with commas


Great idea! Whitespace is overrated. And if I used comma, I could use spacebar as a leader key since I wouldn't need it anymore for coding


Two of those three are error level linters at work!


I do wonder which ones and why :thinking_face: It is always great to get your take on your choices 🙇


"missing docstring" (on public vars) and "require is not alphabetically sorted" (in ns).


Thanks. Do you have a team process to decide what to include on linters?


There's only two backend devs so there's not really a process but we do discuss this stuff. I just noticed that the missing docstring linter is a warning, not an error. We don't enforce that rule on very small, very obvious functions. And I tend to write more docstrings than my teammate -- because I tend to design my code by writing function signatures and docstrings first, and then writing the code to satisfy that prose. But that does have the disadvantage that the docstrings and code can get out of sync over time (which is another reason we don't require docstrings -- better no docstring than an incorrect one).


Thanks for the explanation. Knowing your team size also helped put in context other answers from you that I found sort of puzzling in the past related to the absence of conflicts when changing code. 👍


Hah, well, we have a lot of different applications/services in the same monorepo and tend to work independently on them so conflicts would be rare even if we scaled up our team, I suspect. We also have very few long-lived branches, have automated CI/CD to our staging environment, and automated deploys to production, which all contributes to reducing conflicts.


CI auto-merges master to every PR when running tests so conflicts against master, at least, would be caught immediately.


We noticed that usage of a certain macro is dangerous in our code base. Therefore we made a decision to not use that macro from certain library. Now I am wondering if this rule can be forced with clj-kondo. Is it possible somehow to add project rules like :not-recommended-macros ["my-ns/my-macro-fn"]which will generate a warning?


There is an issue here: Please upvote and/or comment. Right now you can accomplish a similar effect using the hooks API. Write a hook which emits a warning when the macro is called. After that, just return nil in your hook code to continue linting as usual.


Thanks for the info. I will take a look


Btw, if your company is using clj-kondo, would you mind leaving a message here? Then I can list your company on the companies page, if you want.


Thanks for the example. Listing our company as a clj-kondo user sounds good. I will double check internally that it is ok and post a message to the discussion.

🎉 1

Made some docs around how you can use hooks to disrecommend a call to a function or macro:

Noah Bogart15:10:14

excellent, thank you very much