google / google/google-java-format
Inconsistent line-length formatting between files with CRLF and files with LF line endings
- Vorherrschende Sprache
- Java
- Sterne
- 6.2k
- Forks
- 937
- Ø Merge
- 6 Min.
- Gemergte PRs (30 T.)
- 3
Beschreibung
## Setup
**Version:** google-java-format-1.7-all-deps.jar
**Machines:**
- MacOS 10.14.5
- Fedora Linux 30
## Problem
The formatter splits lines inconsistently when the file has CRLF line endings vs. LF line endings. Specifically, when a line is 100 characters long ([the max for the formatter](https://github.com/google/google-java-format/blob/64242e17f5478eb07a2ca7e409382271765f2524/core/src/main/java/com/google/googlejavaformat/java/Formatter.java#L90)) and the file has CRLF line endings, the formatter will split the line prematurely.
This happens at the command line and when using the formatter in _IntelliJ 2019.1.3_.
## Expected behavior
Line endings should not change the behavior of the formatter with respect to line length.
## Steps to Reproduce
```java
public class Something {
private static enum Response {
ONE;
}
// This is not a Rest API method(end point).
public Response aaaaaBbbbbbCccccccc(int aaaaaaCcccccccDd, String aaaaaaCcccccccEeee) {
try {
// ...other code was here...
// check if client universe name provided by UI is null
if (aaaaaaCcccccccEeee == null) {
return DdddEeeeConstants.SOMETHING_TYPE.equals(aaaaaaCccccccc.getAaaaaaCcccccccTttt())
? RestUtils.buildDDResponse(
DDExceptionUtils.getStatusMessageFromList(DDStatusCodeConstants.DD_CODE_25003)) /*
* Watchlist name is needed for processing this request.
*/
: RestUtils.buildDDResponse(
DDExceptionUtils.getStatusMessageFromList(DDStatusCodeConstants.DD_CODE_25002)); /*
* Portfolio name is needed for processing this request.
*/
}
// ...other code was here...
return ONE;
} catch (FFFGgggException e) {
return RestUtils.handleBusinessException(e);
} catch (Exception e) {
return RestUtils.handleSystemException(e);
}
}
}
```
1. Copy the code above into a file named `with-lf.java`, and a file named `with-crlf.java`
1. Ensure each file has the proper line endings
1. Run `dos2unix` on `with-lf.java` (or use an editor in which you can control the line endings)
1. Run `unix2dos` on `with-crlf.java` (or use an editor in which you can control the line endings)
1. Run `java -jar /path/to/google-java-format-1.7-all-deps.jar -r /path/to/with-lf.java`
1. Run `java -jar /path/to/google-java-format-1.7-all-deps.jar -r /path/to/with-crlf.java`
1. Run `diff -uw /path/to/with-crlf.java /path/to/with-lf.java` to see the differences
Beitragsleitfaden
Bewertung
Dieses Issue wurde noch nicht bewertet.