Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Line Seperator issue between windows and unix

Đang mở
#604 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
java
Lĩnh vực
tooling

Hướng nghiên cứu

Tái hiện sự khác biệt bằng cách sử dụng google-java-format-1.10.0-all-deps.jar và ví dụ MinimalExample.java với cả kết thúc dòng LF và CRLF. Truy tìm lý do formatter tạo ra cách xuống dòng khác nhau, sau đó xác minh rằng việc định dạng cùng một mã nguồn cho đầu ra nhất quán, không có thêm một lần xuống dòng, trên cả hai nền tảng.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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)

Ngôn ngữ chính
Java
Star
6.2k
Fork
936
Merge trung bình
6 phút
Pull request đã merge (30 ngày)
3

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của google/google-java-format

Tất cả issue của google/google-java-format

Issue tương tự

Thêm issue về Java

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.