Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort requires alphabetically without removing unused requires #598

Closed
dani-mp opened this issue Mar 26, 2020 · 17 comments
Closed

Sort requires alphabetically without removing unused requires #598

dani-mp opened this issue Mar 26, 2020 · 17 comments

Comments

@dani-mp
Copy link

dani-mp commented Mar 26, 2020

Calva’s clj-kondo helps me detect when a require is not alphabetically sorted, but I’d love if Calva formats this automatically when I save the file, can it be done?

@dani-mp
Copy link
Author

dani-mp commented Mar 26, 2020

There's some work done already here: https://github.com/immoh/nsorg/

@il-tmfv
Copy link

il-tmfv commented Mar 27, 2020

A good thing to have, but, please make it configurable via settings. I mean Format on save part.
Autoformat might make things harder if you want to keep your PR cleaner.

@PEZ
Copy link
Collaborator

PEZ commented Mar 27, 2020

I think the first step here would be to make it on demand. So when you see kondo complain about this, you can issue the command to clean it up.

@dani-mp
Copy link
Author

dani-mp commented Mar 27, 2020

I guess a nice goal could be that it plays nicely with the linter. This past couple of years I've worked in several JavaScript projects and ESLint and Prettier would respect/help each other so there are no conflicts between their configurations.

@borkdude
Copy link

Yes please!

@borkdude
Copy link

For reference, Emacs clojure-mode has this as clojure-sort-ns:

https://github.com/clojure-emacs/clojure-mode/blob/da9f1ec717dac1194404b4a4562dba6bd9a4ee3a/clojure-mode.el#L1848

@bpringe
Copy link
Member

bpringe commented Aug 19, 2020

It seems this might be the best path: https://github.com/clojure-emacs/refactor-nrepl#clean-ns

@bpringe
Copy link
Member

bpringe commented Dec 23, 2020

I believe we can soon do this via clojure-lsp 🎉

@bpringe
Copy link
Member

bpringe commented Dec 27, 2020

This has been released. See the clean-ns refactoring: https://calva.io/refactoring/#commands

@bpringe bpringe closed this as completed Dec 27, 2020
@borkdude
Copy link

@bpringe With all respect, clean ns is not the same as just ns sorting. I don't want a tool to remove requires automatically for me, to be honest.

@bpringe
Copy link
Member

bpringe commented Dec 28, 2020

Oh, my apologies. Reopening this.

@bpringe bpringe reopened this Dec 28, 2020
@bpringe bpringe changed the title Sort requires alphabetically Sort requires alphabetically without removing unused requires Dec 28, 2020
@dani-mp
Copy link
Author

dani-mp commented Dec 30, 2020

Remove requires automatically can be super useful, but it's true that if it's happening on save, it can get in the middle of your workflow.

@bpringe
Copy link
Member

bpringe commented Dec 30, 2020

To be clear, clean-ns is only run manually via a command, currently.

@borkdude
Copy link

Coming from emacs, I like that you have just clojure-sort-ns which isn't that intrusive as something which rewrites your ns form. So it would be nice if we could also have that option, while clean-ns does this and more.

@PEZ PEZ removed the enhancement label Feb 10, 2021
@PEZ
Copy link
Collaborator

PEZ commented Dec 19, 2023

@ericdallo is the clojure-lsp extra command sort-clauses the way to do this? It seems to work if I with the cursor outside the (:require ...) form do Quick Fix and select Sort List. But maybe it really just “ seems” to work. 😄

@ericdallo
Copy link
Contributor

@PEZ I never tested with require form because clean-ns most of the time is enough for most people and me, but seems like it should work as well 😆, and maybe we could improve it if we find anything not working as seems to makes sense to live in that code action.
Said that, I'd say we have already a working command/code-action that does what OP wants

@PEZ
Copy link
Collaborator

PEZ commented Dec 24, 2023

Thanks, @ericdallo. I'll close this for now then, as being implemented via the Sort List quick fix. We can reopen or open a new issue if we see that we need something more than this.

@PEZ PEZ closed this as completed Dec 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants