diff --git a/lib/standard-clojure-style.js b/lib/standard-clojure-style.js index e2ac7d7..1efb11c 100644 --- a/lib/standard-clojure-style.js +++ b/lib/standard-clojure-style.js @@ -1172,10 +1172,6 @@ return rtrim(strReplace(txt, /^[, ]*\n+ */, '')) } - function removeTrailingWhitespace (txt) { - return strReplace(txt, /[, ]*$/, '') - } - function txtHasCommasAfterNewline (s) { return /\n.*,.*$/.test(s) } @@ -3350,7 +3346,7 @@ ignoreNodesStartId = startIgnoreNode.id ignoreNodesEndId = closingNode.id - // if a node without children, then just don't format it + // if a node without children, then just don't format it } else { ignoreNodesStartId = startIgnoreNode.id ignoreNodesEndId = firstNodeInsideIgnoreZone.id @@ -3359,8 +3355,8 @@ } if (isParenOpener(node)) { - // we potentially need to add this opener node to the current openingLineNodes - // before we push into the next parenStack + // we potentially need to add this opener node to the current openingLineNodes + // before we push into the next parenStack const topOfTheParenStack = stackPeek(parenStack, 0) if (topOfTheParenStack) { const onOpeningLineOfParenStack = lineIdx === topOfTheParenStack._parenOpenerLineIdx @@ -3449,7 +3445,7 @@ } if (lookForwardToSlurpNodes) { - // look forward and grab any closers nodes that may be slurped up + // look forward and grab any closers nodes that may be slurped up const parenTrailClosers = findForwardClosingParens(nodesArr, inc(idx)) // If we have printed a whitespace node just before this, we may need to remove it and then re-print @@ -3467,8 +3463,8 @@ const parenTrailCloserNode = parenTrailClosers[parenTrailCloserIdx] if (isParenCloser(parenTrailCloserNode)) { - // NOTE: we are adjusting the current line here, but we do not update the nodesWeHavePrintedOnThisLine - // because we cannot have a Rule 3 alignment to a closer node + // NOTE: we are adjusting the current line here, but we do not update the nodesWeHavePrintedOnThisLine + // because we cannot have a Rule 3 alignment to a closer node lineTxt = strConcat(lineTxt, parenTrailCloserNode.text) parenTrailCloserNode.text = '' @@ -3489,7 +3485,7 @@ } if (currentNodeIsNewline) { - // record the original column indexes for the next line + // record the original column indexes for the next line nodesArr = recordOriginalColIndexes(nodesArr, idx) const numSpacesOnNextLine = numSpacesAfterNewline(node) @@ -3596,16 +3592,16 @@ if (topOfTheParenStack && topOfTheParenStack._rule3Active) { numSpaces = topOfTheParenStack._rule3NumSpaces - // Comment lines that are vertically aligned with a node from the line above --> align to that node + // Comment lines that are vertically aligned with a node from the line above --> align to that node } else if (nextLineContainsOnlyOneComment && commentLooksAlignedWithPreviousForm) { numSpaces = colIdxOfSingleLineCommentAlignmentNode - // Comment lines that are outside of a parenStack, and have no obvious relation to lines above them: - // keep their current indentation + // Comment lines that are outside of a parenStack, and have no obvious relation to lines above them: + // keep their current indentation } else if (nextLineContainsOnlyOneComment && !topOfTheParenStack) { numSpaces = numSpacesOnNextLine - // Else apply regular fixed indentation rules based on the parenStack depth (ie: Tonsky rules) + // Else apply regular fixed indentation rules based on the parenStack depth (ie: Tonsky rules) } else { numSpaces = numSpacesForIndentation(topOfTheParenStack) } @@ -3626,8 +3622,7 @@ // add this line to the outTxt and reset lineTxt if (strTrim(lineTxt) !== '') { - const whitespaceTrimmedLineTxt = removeTrailingWhitespace(lineTxt) - outTxt = strConcat(outTxt, whitespaceTrimmedLineTxt) + outTxt = strConcat(outTxt, lineTxt) } outTxt = strConcat(outTxt, newlineStr) diff --git a/test_format/format.eno b/test_format/format.eno index 97b9891..8e02597 100644 --- a/test_format/format.eno +++ b/test_format/format.eno @@ -1700,3 +1700,21 @@ false} "aaa" --Expected + +# GitHub Issue #123 - eol commas inside comments + +> https://github.com/oakmac/standard-clojure-style-js/issues/123 + +--Input +;; foo, bar, +;; biz, baz, +gee, gaz, +hee, haz, +--Input + +--Expected +;; foo, bar, +;; biz, baz, +gee, gaz +hee, haz +--Expected