oakmac / standard-clojure-style-js

Standard Clojure Style in JavaScript
ISC License
84 stars 1 forks source link

ns require indentation does not adhere to indentation rule 2 #87

Closed imrekoszo closed 1 month ago

imrekoszo commented 2 months ago
(ns my.company.core (:require [clojure.string :as str]))

is currently (@chrisoakman/standard-clojure-style@0.3.0) formatted to

(ns my.company.core
  (:require
    [clojure.string :as str]))

as opposed to

(ns my.company.core
  (:require
   [clojure.string :as str]))

Rule 2:

Other multi-line lists, vectors, maps and sets are aligned with the first element (1 or 2 spaces)

Edit: applies to other clauses as well:

(ns com.example.my-application.server
  "Example application HTTP server and routing."
  (:refer-clojure :exclude [atom count deref distinct empty first])
  (:require-macros
    [cljs.pprint :as pp])
  (:require
    [clojure.core.async :as async :refer [<! <!! >! >!!]]
    [com.example.my-application.base]
    [com.example.my-application.server.sse :as server.sse]
    [io.pedestal.http :as http]
    [io.pedestal.http.sse :as http.sse]
    [ring.util.response :as response])
  (:import
    (java.nio.file Files LinkOption)
    (org.apache.commons.io FileUtils))
  (:gen-class
    :init ctor
    :constructors undefined))
NoahTheDuke commented 2 months ago

I would expect that lists starting with keywords (function application in most cases) are treated as symbols for the purpose of indentation.

imrekoszo commented 2 months ago

I would expect that lists starting with keywords (function application in most cases) are treated as symbols for the purpose of indentation.

I don't have a very strong opinion about this, it's just that my understanding of @tonsky's rule 1 is that it's only about symbols.

oakmac commented 2 months ago

I can see this either way. I think I prefer the 2 space indentation as it creates a stronger indentation impression, especially with reader conditionals.

The good news is: as the ns form is always "printed from scratch" it will always be consistent regardless of the initial input format.

imrekoszo commented 2 months ago

@oakmac are you looking to apply that 2 space indentation to other lists-starting-with-a-keyword as well, i.e. treating keywords as symbols for this purpose as Noah suggests, or are you looking to only do 2 spaces for the ones in the ns form? My personal preference would be consistency between the two.

tonsky commented 2 months ago

My 2 cents:

  ((abc)
    def)

we had to make exception (1 space) for when first place is list/vector/map.

So now we have a situation:

But the rest is up to intepretation.

One can make a case that then reader macro will look off:

#?(:clj ...
    :cljs ...)

Also lists when they are just lists:

'(1
   2
   3)

So it looks like any list with non-symbol in first place should be 1-space indented?

oakmac commented 1 month ago

Some thoughts on this:

My personal preference is two-space indentation (how it works now), but I am leaning toward one-space indentation in order to match how to ns. This project has taken a lot of guidance from those recommendations, so I think it makes sense to follow it here.

It also seems like one-space indentation is far more common than two space:

oakmac commented 1 month ago

PR-130 adjusts ns indentation to match closer with the dominant community style