Fork me on GitHub
#lsp
<
2022-05-09
>
fuad08:05:14

Upon adding a missing libspec, LSP changes the formatting of the ns form. Is that an opinionated change on LSP’s side or is it following some cljfmt config that I’m not aware of?

fuad08:05:39

Before

(ns foo
  (:require [clojure.spec.alpha :as s])
  (:import [java.util Date])
After
(ns foo
  (:require
    [clojure.spec.alpha :as s])
  (:import
    [java.util Date])

dharrigan08:05:13

Reformating the ns after adding a libspec is on by default.

dharrigan08:05:30

You can toggle it off.

ericdallo11:05:14

Wait, it's better to configure the clean-ns to keep imports on :same-line

ericdallo11:05:24

Before you disable clean ns totally..

ericdallo11:05:49

clojure-lsp does that as default because it's the recommended by clojure style guide, but since it's common to have that formatting as well like Nubank has, clojure-lsp allows you to use it as well

fuad16:05:05

Interesting, thanks! I didn’t know that clojure-style-guide encouraged the line break. I don’t have a strong opinion so now I’ll consider adopting it.

👍 2
fuad16:05:25

It’ll be hard to enforce though since cljfmt apparently doesn’t support formatting ns forms

ericdallo16:05:57

But clojure-lsp has it, if you add clojure-lsp to your CI

👀 1
tangrammer14:05:34

Hi guys! anyone could point me how clojure-lsp could use the :node conditional reader instead of :clj one? my clojure ns contains following required namespace

#?(:browser
     (:require
      [com.kubelt.lib.http.browser :as lib.http])
     :node
     (:require
      [com.kubelt.lib.http.node :as lib.http])
     :clj
     (:require
      [com.kubelt.lib.http.jvm :as lib.http]))
and inside the ns there is (lib.http/->HttpClient) but i got Unresolved namespace lib.http. Are you missing a require? [unresolved-namespace] and my ns com.kubelt.lib.http.node exists in the proper place/folder It seems that it always tries to read the :clj ns, thus when i navigate to lib.http i go to com.kubelt.lib.http.jvm

ericdallo14:05:13

I'm not aware there was a :node conditional reader 😂 , does clj-kondo support it as well @U04V15CAJ?

ericdallo14:05:44

shouldn't that be a :cljs ? I really don't know

borkdude14:05:08

I don't think that is a #clojurescript thing

borkdude14:05:22

Probably a shadow-cljs thing

tangrammer14:05:19

yep I imagine it's related with shadow-cljs 🙂

tangrammer15:05:07

could be any workaround for that kind of projects?

ericdallo15:05:10

I can't see a way out without changing anything on clj-kondo side

ericdallo15:05:46

maybe you could add a :cljs conditional duplicating those requires, not sure how bad would be that tho

1
borkdude15:05:48

clj-kondo only supports :clj and :cljs

borkdude15:05:08

we could make it more flexible but that's not been necessary so far

👍 1
borkdude15:05:39

but we probably should

borkdude15:05:12

There is already a :cljc {:features [:clj]} config which only lints the project for clojure

borkdude15:05:29

but we would need :cljc {:features [:node :browser :clj]} and some mapping that tells clj-kondo what :node means, e.g. :cljc {:lint-feature-as {:node :cljs}}

borkdude15:05:03

Could you create an issue about that?

borkdude15:05:54

I want the solution to be more general than node, I'll change the title a bit

👍 1
tangrammer15:05:20

seems much better now 🙂