google / google/google-java-format

Inconsistent line-length formatting between files with CRLF and files with LF line endings

Ouverte
#380 0 commentaires 3 réactions 0 personnes assignées Voir sur GitHub
Langage dominant
Java
Étoiles
6.2k
Forks
937
Merge moyen
6 min
PR mergées (30 j)
3

Description

## 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

Guide de contribution

Ouvrir le guide de contribution

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.