Skip to content

[DRAFT] Issue #193 - rule 3 alignment edge cases #195

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ npx @chrisoakman/standard-clojure-style fix src-clj/ src-cljs/ test/

See the **Command Line Usage** section below for more options.

Please [open an issue] when Standard Clojure Style breaks your code :upside_down_face:
Please [open an issue] if Standard Clojure Style breaks your code :upside_down_face:

[open an issue]:https://github.com/oakmac/standard-clojure-style-js/issues/new

Expand Down Expand Up @@ -70,10 +70,9 @@ your editor, on the web, CLI tooling, etc.

## Project Status and Stability

As of Nov 2024, I think this formatter is ready for **most** Clojure
codebases. There are still [some outstanding bugs] that I want to fix before
releasing v1.0.0, but I do not want this project to live in "pre-1.0"
forever.
As of April 2025, this formatter is ready for **most** Clojure codebases. There
are still [some outstanding bugs] that I want to fix before releasing v1.0.0,
but I do not want this project to live in "pre-1.0" forever.

[some outstanding bugs]:https://github.com/oakmac/standard-clojure-style-js/labels/v1%20blocker

Expand Down
23 changes: 22 additions & 1 deletion lib/standard-clojure-style.js
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,27 @@
return nodeContainsText(node) && charAt(node.text, 0) !== ' '
}

// Is this a .marker node that can act as a Rule 3 alignment point?
function isMarkerNodeRule3AlignmentPoint (node) {
return node && node.name === '.marker' && (node.text === '@' || node.text === "'" || node.text === '`' || node.text === '~' || node.text === '~@')
}

function nodeCanBeARule3AlignmentPoint (nodes, nodeIdx) {
const node = nodes[nodeIdx]
const prevIdx = dec(nodeIdx)
let prevNode = null
if (prevIdx >= 0) {
prevNode = nodes[prevIdx]
}
const nodeContainsText = isNodeWithNonBlankText(node)

if (nodeContainsText && prevNode && isMarkerNodeRule3AlignmentPoint(prevNode)) {
return false
} else {
return nodeContainsText
}
}

function isNsNode (node) {
return node.name === 'token' && node.text === 'ns'
}
Expand Down Expand Up @@ -3742,7 +3763,7 @@
if (openingLineNode) {
// Is the first node on this new line vertically aligned with any of the nodes
// on the line above that are in the same paren stack?
if (pastFirstWhitespaceNode && isNodeWithNonBlankText(openingLineNode) && openingLineNode._origColIdx === numSpacesOnNextLine) {
if (pastFirstWhitespaceNode && nodeCanBeARule3AlignmentPoint(topOfTheParenStack._openingLineNodes, openingLineNodeIdx) && openingLineNode._origColIdx === numSpacesOnNextLine) {
// Rule 3 is activated 👍
topOfTheParenStack._rule3Active = true

Expand Down
Loading