Add line-endings argument to enforce specific newline format (fix Windows compatibility issues)#57
Open
seaburger wants to merge 4 commits intojumanjihouse:masterfrom
Open
Add line-endings argument to enforce specific newline format (fix Windows compatibility issues)#57seaburger wants to merge 4 commits intojumanjihouse:masterfrom
seaburger wants to merge 4 commits intojumanjihouse:masterfrom
Conversation
Merged
this allows overriding the default line endings when writing files and is intended for formatting then linting output in windows environments.
e1dd710 to
a3c6304
Compare
Contributor
Author
|
@jumanjiman This PR is now ready to review/merge. I rebased and updated this code after the other windows compatibility fix in #58 got merged to master. If you merge this could you also add a tag Thanks 😃 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
There is an issue on Windows when using this formatter when combined with a linter that is configured to accept only
\nnewlines. Whenpre-commit-hook-yamlfmtruns, the newlines used for file writes depends on the OS.Python uses
os.linesepby default which means on Windows this is\r\nand on POSIX it is\nhttps://docs.python.org/3/library/functions.html#open-newline-parameter
With linter validation running after this formatter, you get stuck in a loop.
\nin the YAML files and commityamlfmtrewrites file with\r\nline endingsyamllintfails since it wants\nline endings (withnew-lines: enabled)Example scenario of this happening: netbox-community/devicetype-library#1361 (comment)
This PR adds an optional
--line-endingsargument which allows overriding this default python behavior. This allows projects to explicitly specify the line ending format they need for their use case and support multiple development platforms.This is implemented by simply using the
newlineparameter on theopen()call for file writes.Tests have been added to cover:
--line-endingsprovided (i.e. all current use of this formatter)--line-endings lf--line-endings crlf--line-endings cr