Fork me on GitHub
#lsp
<
2022-06-13
>
borkdude13:06:57

@ericdallo There is a conflict between how clj-kondo reports unsorted namespaces and how lsp-organize-import sorts them.

(ns example
  (:require
   ["prism-react-renderer$default.default" :as Highlight]
   ["prism-react-renderer$default.Prism" :as Prism]
   [reagent.core :as r]
   [reagent.dom.server :as srv]))
Here the capitalized suffix should go before, because capitals are before small letters sorting-wise. Clj-kondo reports this but when you fix it manually and then run lsp-organize-imports, clojure-lsp reverts it.

Noah Bogart13:06:39

Seems like a bug in clj-kondo? I would expect case-insensitive sorting.

borkdude13:06:15

It's not a bug, always been like this, there is no such thing as case insensitive sorting in clj-kondo.

borkdude13:06:52

Note that clojure-sort-ns is consistent here

👍 1
ericdallo13:06:56

I'll take a look soon

ericdallo15:06:50

To be honest I was not aware of that clj-kondo linter, I'll enable for clojure-lsp repo to help with those kind of issues

borkdude15:06:16

I always enable it in my home config

ericdallo15:06:53

it'd be nice to have it enabled as default, but It would probably cause lots of headaches for most users

ericdallo15:06:25

@U04V15CAJ I found we already have a setting for that:

:clean {:sort {:require :lexicographically}}

ericdallo15:06:39

I wonder why it's not default/if it will cause any other undesired harm

ericdallo15:06:44

if not, we should make it default

borkdude15:06:45

it is the default of tooling prior to clojure-lsp, like clojure-sort-ns which is why clj-kondo warns about it like this. having multiple options just creates more confusion imo

👆 1
ericdallo15:06:27

I agree, if this setting changes only this behavior, I'm ok changing it, but if causes any other behavior that should not be default we need to think more about it

ericdallo15:06:39

I'll take a closer look, but I think this setting can break other cases

snoe15:06:01

we only had it lexicographic originally, not sure why it wasnt kept as default.

ericdallo15:06:09

we have https://github.com/clojure-lsp/clojure-lsp/blob/master/lib/src/clojure_lsp/feature/clean_ns.clj#L71-L85, which sorts differently, we need to check if we need to change anything with lexicographic or it will behave ok

ericdallo15:06:50

I think I have a quick fix for that

ericdallo15:06:09

@U0BUV7XSA we were already trying to make sorting lexicographically as default, but not right 😅 , I'll fix it to be lexicographically not needing the lexicographically setting anymore

ericdallo15:06:27

What is the proper way to sort this?

(ns foo.bar
  (:require
   ["foo.bar" :default Foo]
   [ball import1]
   [zebra]
   apple
   ball))
we are sorting like that with the existing lexicographically setting, but kondo says it should be:
(ns foo.bar
  (:require
   ["foo.bar" :default Foo]
   apple
   ball
   [ball import1]
   [zebra]))

ericdallo15:06:46

if you agree kondo is right, I can change that behavior @U0BUV7XSA it's just that it has a test testing that way

snoe15:06:26

top looks right to me.

borkdude15:06:32

@ericdallo strings go first lexicographically, for the dumb reason that " is before a but surrounding vectors are ignored

snoe15:06:50

[ goes first though

ericdallo15:06:12

yeah, kondo doesn't like [ first

borkdude15:06:28

again, clj-kondo respects how other tools always did it and it didn't want to cause any friction with those: clj-kondo only warns, other tools fix (clojure-sort-ns)

borkdude15:06:49

and clojure-sort-ns ignores the vector around the names

ericdallo15:06:51

yeah, I agree with other tools

ericdallo15:06:09

is it ok for you to change to follow other tools standard @U0BUV7XSA?

snoe15:06:11

cursive just had sort lines for the longest time (still?) if you sort lines you end up with the top

snoe15:06:39

vim too. i think they are different sorts.

ericdallo15:06:39

Well remembered @U11BV7MTK, so I think we have 2 differents sorts indeed, but kondo (our main linter) has a preference

ericdallo15:06:04

so we should at least change the default to match kondo I guess? or change kondo to match current clojure-lsp one

borkdude15:06:13

I actually don't care that much which we choose, but if people fix it up with some other tool which then causes lint warnings, that is mostly what I want to prevent

borkdude15:06:37

and clojure-sort-ns was the tool I was using myself for this (and many other people)

ericdallo15:06:52

yeah, for example, if we go with current kondo uses, cursive may complain about it

borkdude15:06:03

but nobody in cursive is using clojure-lsp

👍 1
snoe15:06:17

they do on cli tho

☝️ 2
ericdallo15:06:46

yes, cursive users may not use on editor, but all nubank projects have clojure-lsp as cli tool on CI for example

borkdude15:06:04

ok that sucks then :)

ericdallo15:06:18

yeah, we need to think on the best default

snoe15:06:28

what tool other than clojure-sort-ns uses this sort?

borkdude15:06:48

I think we can prevent the [] discussion by saying: always wrap your ns name in a vector, as the default style

👍 1
borkdude15:06:22

then there's the case insensitivity: I'm open to making this the default in clj-kondo or at least make clj-kondo not complain about either way

ericdallo15:06:24

so, should we have kondo saying that instead of "sort your requires"?

borkdude15:06:36

not instead

snoe15:06:53

does kondo lint other style guide rules? is this one on by default?

borkdude15:06:11

this one is not on by default but I use it in my home config, so I have it on by default in any project

borkdude15:06:28

we could turn the [foo] vs foo linter on if you have the sorting linter enabled

borkdude15:06:07

or just advice that when people complain ;)

borkdude15:06:12

and put it into the docs

ericdallo16:06:41

so should we change anything on clojure-lsp side? We had https://github.com/clojure-lsp/clojure-lsp/issues/561 to on purpose ignore case in sorting

borkdude16:06:51

I'll just make clj-kondo more lenient with case sensitivity then I guess and if people complain, we can make an option to make it more strict again

💯 1
ericdallo16:06:50

Now I see why this linter is not enabled by default 😂 lots of different opinions. I still think it should have something mentioning that on ClojureStyleGuide or something

borkdude16:06:15

I've made the linter lenient before, it should probably only warn on things that are unarguably not sorted by a very broad collection of opinions 🤷

👍 1
borkdude16:06:51

I've had requests to support custom sorting "opinions" in clj-kondo, but I refused since I think we have enough discussion on indentation in the community already ;)

borkdude18:06:34

Btw, one more thing. Often scripts or clerk notebooks have this:

(require '[nextjournal.clerk :as clerk]
         '[babashka.fs :as fs])
and clj-kondo also warns about those, but clojure-lsp does not "organize" this

ericdallo18:06:47

You mean that clojure-lsp ignore requires not inside a ns form?

borkdude18:06:00

it's not super common, but it does happen

ericdallo18:06:06

Alright, please open a issue, I think we should support that somehow

borkdude18:06:07

low priority

borkdude15:06:05

Pushed to master (case insensitivity)

👍 1
ericdallo17:06:11

I will do a release probably tomorrow

borkdude17:06:12

No hurry. I want to get in some more stuff on Wednesday and might release a new clj-kondo then

borkdude10:06:50

Actually the only thing left for me to do is make an macos aarch64 binary and then I'm good to go

ericdallo12:06:48

Right, I think I'll wait for you, we have lots of change so clojure-lsp, that's why I wanted to do a release

borkdude12:06:36

OK, there's also one more linter coming up: discouraged ns 😈 by @U04V4KLKC

👿 1
borkdude12:06:17

I'll ping you when clj-kondo is ready then on Wednesday

👍 1
borkdude18:06:17

Lost track of that classpath issue from recently, but I'm having a case of that again. Navigating to a var in the same project and I end up in gitlibs. This is with clerk (open source project)

ericdallo18:06:50

You mean that there is the same ns both in the project and in the classpath as a git lib dep?

borkdude18:06:38

I don't know why it would be on the classpath - it doesn't appear when I do clojure -Spath

ericdallo18:06:21

Hum, could you add dev:test profiles to that command? clojure-lsp uses it as default aliases

ericdallo18:06:29

Hum, what file/line/col you are seeing that behavior so I can test it later?

borkdude18:06:37

in nextjournal/clerk.clj 264:68

👍 1