Skip to content

Commit

Permalink
GitHub Issue #161 - namespaced map literal alignment (#163)
Browse files Browse the repository at this point in the history
  • Loading branch information
oakmac authored Nov 27, 2024
1 parent f7ed654 commit 37b5b3c
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/standard-clojure-style.js
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,7 @@
}

function isParenOpener (n) {
return n && n.name === '.open' && parenOpenersTbl[n.text]
return n && n.name === '.open' && (parenOpenersTbl[n.text] || isNamespacedMapOpener(n))
}

function isParenCloser (n) {
Expand Down Expand Up @@ -853,6 +853,10 @@
return opener.text === '#('
}

function isNamespacedMapOpener (opener) {
return opener.name === '.open' && strStartsWith(opener.text, '#:') && strEndsWith(opener.text, '{')
}

function isReaderConditionalOpener (opener) {
// TODO: also check node type here?
return opener.text === '#?(' || opener.text === '#?@('
Expand Down Expand Up @@ -1240,6 +1244,8 @@
return inc(openerColIdx)
} else if (isAnonFnOpener(wrappingOpener)) {
return openerColIdx + 3
} else if (isNamespacedMapOpener(wrappingOpener)) {
return openerColIdx + strLen(wrappingOpener.text)
} else {
// else indent two spaces from the wrapping opener
return inc(inc(openerColIdx))
Expand Down
53 changes: 53 additions & 0 deletions test_format/format.eno
Original file line number Diff line number Diff line change
Expand Up @@ -1952,3 +1952,56 @@ hee, haz
[& filters]
`(clojure.core/refer '~'clojure.core ~@filters))
--Expected

# GitHub Issue #161 - namespaced map literals 1

> https://github.com/oakmac/standard-clojure-style-js/issues/161

--Input
(def my-vec
[#:xyz{:aaa "aaa"
:bbb "bbb"
:ccc "ccc"}

#:xyz{:ddd "ddd"
:eee "eee"
:fff "fff"}])
--Input

--Expected
(def my-vec
[#:xyz{:aaa "aaa"
:bbb "bbb"
:ccc "ccc"}

#:xyz{:ddd "ddd"
:eee "eee"
:fff "fff"}])
--Expected


# GitHub Issue #161 - namespaced map literals 2

> https://github.com/oakmac/standard-clojure-style-js/issues/161

--Input
(def my-vec
[#:xyz{:aaa "aaa"
:bbb "bbb"
:ccc "ccc"}

#:xyz{:ddd "ddd"
:eee "eee"
:fff "fff"}])
--Input

--Expected
(def my-vec
[#:xyz{:aaa "aaa"
:bbb "bbb"
:ccc "ccc"}

#:xyz{:ddd "ddd"
:eee "eee"
:fff "fff"}])
--Expected

0 comments on commit 37b5b3c

Please sign in to comment.