Skip to content

Sort dependencies in project.clj #121

Description

@thumbnail

Context

Our lein-template adds ;; Please keep the dependencies sorted a-z. before the :dependencies-key in project.clj.

There's benefits for sorting this list (friction-free merges, improves readability, ..)

Task

We need a formatter to sort the dependency list

Acceptance criteria

dependency sorting:

(defproject corpus "unreleased"
  :dependencies [[c]
                 [a]])

should be formatted to

(defproject corpus "unreleased"
  :dependencies [[a]
                 [c]])

:exclusion sorting

(defproject corpus "unreleased"
  :dependencies [[a
                  :exclusions [c b]])

should be formatted to

(defproject corpus "unreleased"
  :dependencies [[a
                  :exclusions [b 
                               c]])

note the formatted newlines

Additional resources

inspiration for replacement of the :dependencies can be found here:

(speced/defn replace-ns-form!

sorting might be something like:

(let [deps '[[c] 
             [a :exclusions [c b]]]]
  (->> deps
       (mapv (fn [clause]
               (let [exclusion-index (.indexOf clause :exclusions)]
                 (if (> 0 exclusion-index)
                   clause
                   (update clause (inc exclusion-index) (comp vec sort))))))
       (sort-by first)
       (vec)))
=> [[a :exclusions [b c]] [c]]

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions