Skip to content
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

Keep column alignment paddings does not respect line continuation #390

Closed
dcsobral opened this issue Jun 12, 2019 · 3 comments
Closed

Keep column alignment paddings does not respect line continuation #390

dcsobral opened this issue Jun 12, 2019 · 3 comments

Comments

@dcsobral
Copy link

I expected this code snippet not to be reformatted when using shfmt -kp -ci 2 -d:

     curl -X POST -d '{
         "ref": "refs/tags/'"$TAG"'",
         "sha": '"$TAG_SHA"'
-      }'                                             \
-      -H "Content-Type: application/json"            \
+      }' \
+      -H "Content-Type: application/json" \
       -H "Authorization: token $GITHUB_ACCESS_TOKEN" \
       "https://api.github.com/repos/${TRAVIS_REPO_SLUG}/git/refs"

Specifically, I'd expect \ not to be moved when -kp is used. Issue #344 is related, though not the same.

@mvdan
Copy link
Owner

mvdan commented Jun 13, 2019

This indeed seems like a bug. Thanks for reporting.

@mvdan
Copy link
Owner

mvdan commented Jun 19, 2019

Hmm, this is trickier than I thought because we don't record any position information for escaped newlines, so we can't at the moment preserve the padding/alignment.

@mvdan
Copy link
Owner

mvdan commented Oct 13, 2019

I'm not going to work on this. -kp works on tokens, and escaped newlines are not tokens. They are skipped by the parser (just like in all shells), and they are only encoded in the syntax tree by how the previous and following tokens are on different lines.

So we don't have the information necessary to know in what column an escaped newline was. Adding that would complicate the parser and syntax tree, and I just don't think it's worth the effort. Closing for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants