From 640e671040d3f9ae4b02effd60d31fdabb99e791 Mon Sep 17 00:00:00 2001 From: Chris Oakman Date: Fri, 28 Feb 2025 09:47:23 -0600 Subject: [PATCH 1/3] WIP - add test cases --- test_format/format.eno | 68 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/test_format/format.eno b/test_format/format.eno index 5399f09..aabe46e 100644 --- a/test_format/format.eno +++ b/test_format/format.eno @@ -2175,3 +2175,71 @@ com.example.my-app) [] (println "boop")) --Expected + +# GitHub Issue #189 - set alignment bug 1 + +--Input +#{1 + 2 + 3 + 4} +--Input + +--Expected +#{1 + 2 + 3 + 4} +--Expected + +# GitHub Issue #189 - set alignment bug 2 + +--Input +#{[1] + [2] + [3] + [4]} +--Input + +--Expected +#{[1] + [2] + [3] + [4]} +--Expected + +# GitHub Issue #189 - set alignment bug 3 + +--Input +#{1 + [2] + 3 + [4] + 5} +--Input + +--Expected +#{1 + [2] + 3 + [4] + 5} +--Expected + +# GitHub Issue #189 - set alignment bug 4 + +--Input +#{[1] + 2 + [3] + 4 + [5]} +--Input + +--Expected +#{[1] + 2 + [3] + 4 + [5]} +--Expected From af8ffd7c61b1ad6f5814f745328c4fa8cc844311 Mon Sep 17 00:00:00 2001 From: Chris Oakman Date: Fri, 28 Feb 2025 14:08:30 -0600 Subject: [PATCH 2/3] WIP - fix --- lib/standard-clojure-style.js | 48 ++++++++++++++++------ test_format/format.eno | 76 +++++++++++++++++++++++++++++++++++ 2 files changed, 112 insertions(+), 12 deletions(-) diff --git a/lib/standard-clojure-style.js b/lib/standard-clojure-style.js index e67ead1..ae59ee6 100644 --- a/lib/standard-clojure-style.js +++ b/lib/standard-clojure-style.js @@ -858,26 +858,36 @@ return nodeContainsText(n) && !isWhitespaceNode(n) } - function isOneSpaceOpener (opener) { - // TODO: also check node type here? - return opener.text === '{' || opener.text === '[' + function isMapLiteralOpener (n) { + return n && n.name === '.open' && n.text === '{' } - function isAnonFnOpener (opener) { - return opener.text === '#(' + function isVectorLiteralOpener (n) { + return n && n.name === '.open' && n.text === '[' } - function isNamespacedMapOpener (opener) { - return opener.name === '.open' && strStartsWith(opener.text, '#:') && strEndsWith(opener.text, '{') + function isSingleParenOpener (n) { + return n && n.name === '.open' && n.text === '(' } - function isReaderConditionalOpener (opener) { - // TODO: also check node type here? - return opener.text === '#?(' || opener.text === '#?@(' + function isAnonFnOpener (n) { + return n && n.name === '.open' && n.text === '#(' + } + + function isSetLiteralOpener (n) { + return n && n.name === '.open' && n.text === '#{' + } + + function isNamespacedMapOpener (n) { + return n && n.name === '.open' && strStartsWith(n.text, '#:') && strEndsWith(n.text, '{') + } + + function isReaderConditionalOpener (n) { + return n && n.name === '.open' && (n.text === '#?(' || n.text === '#?@(') } function isOpeningBraceNode (n) { - return n.name === 'braces' && isArray(n.children) && arraySize(n.children) === 3 && n.children[2].name === '.close' && n.children[2].text === '}' + return n && n.name === 'braces' && isArray(n.children) && arraySize(n.children) === 3 && n.children[2].name === '.close' && n.children[2].text === '}' } function commentNeedsSpaceBefore (lineTxt, nodeTxt) { @@ -1282,8 +1292,22 @@ if (isReaderConditionalOpener(wrappingOpener)) { return directlyUnderneathOpener } else if (nextNodeAfterOpener && isParenOpener(nextNodeAfterOpener)) { + if (isMapLiteralOpener(wrappingOpener)) { + return inc(openerColIdx) + } else if (isVectorLiteralOpener(wrappingOpener)) { + return inc(openerColIdx) + } else if (isSingleParenOpener(wrappingOpener)) { + return inc(openerColIdx) + } else if (isSetLiteralOpener(wrappingOpener)) { + return inc(inc(openerColIdx)) + } else if (isAnonFnOpener(wrappingOpener)) { + return inc(inc(openerColIdx)) + } else { + throw new Error('Error inside numSpacesForIndentation function. This condition should be unreachable.') + } + } else if (isMapLiteralOpener(wrappingOpener)) { return inc(openerColIdx) - } else if (isOneSpaceOpener(wrappingOpener)) { + } else if (isVectorLiteralOpener(wrappingOpener)) { return inc(openerColIdx) } else if (isAnonFnOpener(wrappingOpener)) { return openerColIdx + 3 diff --git a/test_format/format.eno b/test_format/format.eno index aabe46e..874358c 100644 --- a/test_format/format.eno +++ b/test_format/format.eno @@ -2243,3 +2243,79 @@ com.example.my-app) 4 [5]} --Expected + +# GitHub Issue #189 - set alignment bug 5 + +--Input +#{{:a "a"} + :b + [:c]} +--Input + +--Expected +#{{:a "a"} + :b + [:c]} +--Expected + +# GitHub Issue #189 - set alignment bug 6 + +--Input +(defn nested [] + #{{:a "a"} + :b + [:c]}) +--Input + +--Expected +(defn nested [] + #{{:a "a"} + :b + [:c]}) +--Expected + +# GitHub Issue #189 - set alignment bug 7 + +--Input +#{#(:aaa %) + :b + #(:ccc %)} +--Input + +--Expected +#{#(:aaa %) + :b + #(:ccc %)} +--Expected + +# GitHub Issue #189 - set alignment bug 8 + +--Input +#{#{"a"} :a + :b + #(:ccc %) + } +--Input + +--Expected +#{#{"a"} :a + :b + #(:ccc %)} +--Expected + +# GitHub Issue #189 - set alignment bug 9 + +--Input +#{#?(:clj "a" + :cljs "b") + :b + #(:ccc %) + } +--Input + +--Expected +#{#?(:clj "a" + :cljs "b") + :b + #(:ccc %)} +--Expected From fffdde8df113dba3f9d49f64870b25637464d1d9 Mon Sep 17 00:00:00 2001 From: Chris Oakman Date: Fri, 28 Feb 2025 14:35:19 -0600 Subject: [PATCH 3/3] WIP - add another test case --- test_format/format.eno | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test_format/format.eno b/test_format/format.eno index 874358c..30a652c 100644 --- a/test_format/format.eno +++ b/test_format/format.eno @@ -2319,3 +2319,20 @@ com.example.my-app) :b #(:ccc %)} --Expected + +# GitHub Issue #189 - set alignment bug 10 + +--Input +#{ #:xyz{ #:aaa{:a "a" + :b "b"} } + :ccc + :ddd + } +--Input + +--Expected +#{#:xyz{#:aaa{:a "a" + :b "b"}} + :ccc + :ddd} +--Expected