google / google/google-java-format

Line Seperator issue between windows and unix

未關閉
#604 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
Java
星號
6.2k
分支
937
平均合併
6 分鐘
30 天內合併 PR
3

描述

When applying GJF, some code is formatted differently between Unix-style line seperators (LF) and Windows-style line seperators (CRLF). With windows-style an extra linebreak is added, caused by the char difference between LF (\n) and CRLF (\r\n).

I changed the line-separator-style with Intellij (File>File Properties> Line Separators, while having the file opened) and got the following outputs:

Executing `java -jar google-java-format-1.10.0-all-deps.jar MinimalExample.java` when the file is formatted with Unix line endings:

```
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import feign.FeignException;

public class MinimalExample {
void googleJavaFormatWindowsFail() {

FeignException feignException = mock(FeignException.class);
when(feignException.contentUTF8()).thenReturn("""
{
"errorCode" : 420
}
""");
}
}
```

Executing `java -jar google-java-format-1.10.0-all-deps.jar MinimalExample.java` when the file is formatted with Windows line endings:
```
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import feign.FeignException;

public class MinimalExample {
void googleJavaFormatWindowsFail() {

FeignException feignException = mock(FeignException.class);
when(feignException.contentUTF8())
.thenReturn("""
{
"errorCode" : 420
}
""");
}
}
```

If two chars are added, Unix-style generates the same line-break:
```
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import feign.FeignException;

public class MinimalExample {
void googleJavaFormatWindowsFail() {

FeignException feignException = mock(FeignException.class);
when(feignException.contentUTF8())
.thenReturn("""
{
"errorCode" : 42069
}
""");
}
}
```

Done on GJF 1.10.0, 1,9 and 1.8 with Java 15.0.2
Windows 10 10.0
IntelliJ IDEA 2021.1.1 (Community Edition)

貢獻指南

開啟貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。