spotless
spotless copied to clipboard
Add a `PRESERVE` line endings mode
Right now we have UNIX, WINDOWS, PLATFORM_NATIVE, and our default GIT_ATTRIBUTES. These are all "content-blind", in that they can declare the line endings are without looking at the content of the file being formatted.
I'm open to merging a new mode PRESERVE which should work as such:
- Add a parameter
String rawto each of these two methods (this will be**BREAKING**change in/CHANGES.md) - https://github.com/diffplug/spotless/blob/4600bc36f7f23522037b3febf6a98ba6131cfbed/lib/src/main/java/com/diffplug/spotless/LineEnding.java#L126-L131
- Use that string to count the number of
\nand\rcharacters to determine what the correct line ending should be- Some files in the wild will have a mixture of line endings, but preserving that is out-of-scope, we'll pick whichever line ending is more common in the file
- Assuming that the
\rare always paired up as\r\n, then return count_n >= 2 * count_r ? "\n" : "\r\n"
- for
plugin-gradle/CHANGES.mdandplugin-maven/CHANGES.mdthis is just### Added, not breaking
I think that GIT_ATTRIBUTES is what almost everyone should be using, so I'm not going to build PRESERVE myself, but I'd be happy to merge a PR for it if you want it.