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

Remove CRLF line endings #173

Merged
merged 4 commits into from
May 4, 2017
Merged

Remove CRLF line endings #173

merged 4 commits into from
May 4, 2017

Conversation

jbardin
Copy link
Member

@jbardin jbardin commented Nov 30, 2016

Normalize HCL input to use "\n" line endings. The scanner and output
only work with the '\n' character, and "\r\n" newlines can leave
dangling "\r" characters in the parsed output.

@jbardin
Copy link
Member Author

jbardin commented Nov 30, 2016

This should finish up #107, and also takes care of terraform stripping most windows newlines reported in terraform#10381.

@mitchellh
Copy link
Contributor

Hm, so in cases like this I usually try to see what other tools do. The closest in this case is of course go fmt. go fmt enforces \n as the line terminator, and it makes sense our printer works the same way since its based off that. I'd say thats the behavior we should have.

I checked to see what happens with \r\n even in raw strings in Go and they're force converted to \n by fmt, so I think thats fine behavior. Basically, if a user wants explicit \r\n, they need to use a string with "\r\n" explicitly (literally).

I'll change this slightly since I think the only thing to do here is make sure the output doesn't have \r\n.

@mitchellh
Copy link
Contributor

Actually I don't have access very quickly to a Windows machine to run tests atm, at least for the next few days. @jbardin do you mind doing the above? ^

@jbardin
Copy link
Member Author

jbardin commented Dec 1, 2016

SGTM! That makes the change even simpler.

@jbardin jbardin force-pushed the jbardin/crlf branch 2 times, most recently from 0487756 to 1cc5585 Compare December 1, 2016 15:43
@jbardin jbardin changed the title Keep CRLF line endings Remove CRLF line endings Dec 1, 2016
We have test files with both types of line endings, leave them as they
are for tests.
Matching the behavior of Go tooling, we are going to accept "\r\n" line
endings, but standaradize on "\n" being the official format.

Normalize line endings to "\n in the Parse function, so that we
never get stray "\r" characters in the source.
If the canonical newline is a single LF, don't insert CRLF in tests
hcl/parser/test-fixtures/comment.hcl already contained CRLF line
endings.  Convert that to unix and remove the extra cariiage returns
from comment_crlf.hcl.
@jbardin
Copy link
Member Author

jbardin commented Apr 14, 2017

@mitchellh: I forgot about this, but it would be nice to have a single official file format for TF configs. Issues from windows line ending crop up every so often.

@jbardin jbardin merged commit a4b07c2 into master May 4, 2017
@jbardin jbardin deleted the jbardin/crlf branch May 4, 2017 19:02
@tintoy
Copy link

tintoy commented Dec 15, 2017

Hi - stupid question, but if \r\n is simply replaced with \n, won't the positions in the parsed AST be incorrect with respect to the original file contents?

The reason that I ask is I was looking into building an LSP language service for Terraform and would rather avoid writing my own HCL parser if possible. But if the positional information in the AST cannot be relied on when there are Windows-style (or mixed) line endings then that could be tricky.

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

Successfully merging this pull request may close these issues.

None yet

4 participants