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

Retain line separators when generating files #37

Merged
merged 2 commits into from
Apr 10, 2022

Conversation

thumannw
Copy link
Contributor

@thumannw thumannw commented Feb 4, 2022

Nowadays it is standard to work on projects with Unix line endings even under Windows. However, Knit always uses the default system line separator when writing files. This also implies that it always changes the line endings of files whenever it has to update them and the original line ending differs from the system default. This is quite annoying in the aforementioned situation.

This PR offers the following enhancements:

  • Line endings are preserved when the file already exists.
  • A new property defaultLineSeparator (with System.lineSeparator() as default) in the knit extension allows to specify the line separator which shall be used when new files are written.

""".trimMargin()
)
}
return ls ?: System.lineSeparator()
Copy link
Contributor

@qwwdfsad qwwdfsad Apr 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What puzzles me here is whether System.lineSeparator() should be the default.

You've already done a great job with preserving separator for existing files, so the migration for existing users is gradual.

But having system-dependent separator as default behaviour may be not so convenient -- it means that every project using Knit and being developed on multiple platforms have to configure its own line separator (=> also somehow figure out such option exists).

WDYT about making UNIX's \n the default here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for looking at my PRs.

I think it is a good idea to set UNIX style as default.

"""Knit defaultLineSeparator must be one of:
|- Unix (\n)
|- Windows (\r\n)
|- Classic Mac OS (\r)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is rather my libraries-related ranting, so feel free to ignore or object :)

'\r' seems to be a long-dead legacy (OS 9 and long dead classic OS X from 2002) and it's unlikely that someone either uses this machines or actually preserves their convention, so I always strongly object against adding \r to any new code

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was unsure at first what to support, then I just followed what IntelliJ offers (bottom right corner in editor).

I'm fine with just supporting UNIX and WIN. However, one could argue now (even before, but more now) why to pass the line separator explicitly to the extension and not an enum. I think, usually it's awkward in a Gradle script to import enums. Another possibility now would be to switch the two cases with a boolean. Would you like that better?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is completely okay the way it is. Especially when we've changed the default and this option is just a temporary migration mechanism

@thumannw thumannw requested a review from qwwdfsad April 9, 2022 15:29
Copy link
Contributor

@qwwdfsad qwwdfsad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@qwwdfsad qwwdfsad merged commit e6d3231 into Kotlin:main Apr 10, 2022
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

2 participants