Skip to content

Requiring LF line separators isn't Windows-friendly #202

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
bedla opened this issue Jun 20, 2020 · 4 comments
Closed

Requiring LF line separators isn't Windows-friendly #202

bedla opened this issue Jun 20, 2020 · 4 comments
Milestone

Comments

@bedla
Copy link

bedla commented Jun 20, 2020

Hi,
I found that when I run build of spring-javaformat (or any project that uses this tool) on Windows with autocrlf=false it fails on camparations between CRLF and LF.
I think (from my experiment when I was preparing PR) that pass lineSeparator parametr to formatter is easy but what is hard is how to detect eg. from Maven that user is on Windows and uses autocrlf=false.
There is also line.separator system property, but is hard to assign from IDEA/Maven.
It seems that how formatter and autocrlf works it is not possible to set it to false and make it work on Windows. This means that projects (eg. spring-cloud-sleuth) that use this formatter won't work correctly when user clones repository with core.autocrlf=false global Git configuration.
Am I right?
Thx,
Ivos

bedla added a commit to bedla/spring-cloud-sleuth that referenced this issue Jun 20, 2020
Hi,
when authors of spring-javaformat will clarify how to use formatter (see spring-io/spring-javaformat#202) on windows it would be nice to have this clarified in README.
What do you think?
Thx
Ivos
@wilkinsona
Copy link
Contributor

From what I have seen, it won’t just be the formatter that will have problems with line endings on Windows if you use autocrlf=false. We use autocrlf=true in Spring Boot’s Windows CI and don’t have any problems. What is your reason for disabling autocrlf?

@bedla
Copy link
Author

bedla commented Jun 21, 2020

I have autocrlf=false as global config because of some long (I even dont remember why) ago issue with Git and line-ending handling. Maybe I can remove it at my local env, I will investigate it... thx.

Anyways what I have found is, when sources are checked out with LF and formatter runs on Windows reformatted code has line endings that comes from org.eclipse.jdt.internal.compiler.util.Util#LINE_SEPARATOR constant.
I think that this glitch should be documented somehow (maybe here or at spring-cloud docs). What do you think?
Thank you

@wilkinsona
Copy link
Contributor

We've just hit a problem similar to this when upgrading the Spring Initializr project to Checkstyle 8.32. Spring Java Format currently requires LF line endings:

<property name="lineSeparator" value="lf"/>

As mentioned above, we use autocrlf=true in our Windows CI pipelines to ensure that LF line endings in the repository are converted to CRLF line endings on the filesystem. This should have caused Checkstyle to report line ending violations but it did not due to a bug where it only checked the last byte of the line and therefore didn't notice that an LF line ending was in fact a CRLF line ending.

Checkstyle defaults to LF_CR_CRLF which matches LF, CR, or CRLF. We could switch to that. Alternatively we could use SYSTEM which matches whatever System.getProperty("line.separator") returns.

@wilkinsona wilkinsona changed the title Invalid NL handling on Windows with Git core.autocrlf=false Requiring LF line separators isn't Windows-friendly Jul 10, 2020
@snicoll snicoll added this to the 0.0.23 milestone Jul 14, 2020
@philwebb
Copy link
Contributor

I've dropped the attribute so the default of LC_CR_CRLF will be used.

philwebb added a commit that referenced this issue Aug 24, 2020
Update checkstyle rules so that the `NewlineAtEndOfFile` check no
longer enforces only LF line separators. The default now accepts
LF, CR or CRLF.

Closes gh-202
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants