Skip to content
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

Add option to preserve line ending during check/formatting #2277

Closed
kwin opened this issue Sep 26, 2024 · 4 comments · Fixed by #2304
Closed

Add option to preserve line ending during check/formatting #2277

kwin opened this issue Sep 26, 2024 · 4 comments · Fixed by #2304

Comments

@kwin
Copy link
Contributor

kwin commented Sep 26, 2024

Currently the lineEndings option does only allow to configure which line endings to expect. There is no single option which works on non-Git based source code (i.e. extracted from a ZIP source archive) accepting both line endings (Windows and Unix).

This is crucial though because by default source archives created with maven-source-plugin are not normalized with respect to line endings, i.e. the archives end up with Windows endings on a Windows machine and Unix endings on all other machines. As the spotless configuration is part of the source archive, building should not fail with spotless errors irrespective of the line ending.

@nedtwigg
Copy link
Member

the archives end up with Windows endings on a Windows machine and Unix endings on all other machines

PLATFORM_NATIVE should work here, yeah?

@kwin
Copy link
Contributor Author

kwin commented Sep 28, 2024

No, you have arbitrary line endings in the source and it should work with the same config to do spotless:check in Windows and Unix machines. PLATFORM_NATIVE only works if source was created with the same platform, but not if created on a platform with another line ending.

@nedtwigg
Copy link
Member

nedtwigg commented Oct 2, 2024

I'm open to a PRESERVE option here:

/** {@code \n} on unix systems, {@code \r\n} on windows systems. */
PLATFORM_NATIVE,
/** {@code \r\n} */
WINDOWS,
/** {@code \n} */
UNIX,

public interface Policy extends Serializable, NoLambda {
/** Returns the line ending appropriate for the given file. */
String getEndingFor(File file);

Two ambiguous cases:

  • file with zero line endings
  • file with both kinds of line endings

My vote is that both these cases round to "UNIX", but print a warning message.

@kwin
Copy link
Contributor Author

kwin commented Oct 3, 2024

I agree with all you said except for the case

file with both kinds of line endings

In this case I would just throw an exception. This is IMHO never acceptable.

However for performance reasons I would probably just check for the first line ending in a file (and not check all) therefore the first line ending in a file determines the outcome.

@kwin kwin changed the title Add option to normalize line ending prior checking or ignore during check Add option to preserve line ending during check/formatting Oct 3, 2024
kwin added a commit to apache/sling-parent that referenced this issue Nov 13, 2024
This is required to run spotless:check on top of extracted source
archives (outside Git repositories).
Compare with apache/maven-parent#205 and
diffplug/spotless#2277.
kwin added a commit to apache/sling-parent that referenced this issue Nov 13, 2024
This is required to run spotless:check on top of extracted source
archives (outside Git repositories).
Compare with apache/maven-parent#205 and
diffplug/spotless#2277.
kwin added a commit to apache/maven-parent that referenced this issue Dec 6, 2024
Accept all line endings (even outside git repositories), compare with
diffplug/spotless#2277
This closes #205
kwin added a commit to apache/maven-parent that referenced this issue Dec 7, 2024
compare with diffplug/spotless#2277
Update to spotless-m-p 2.44.0.BETA4 

This closes #205
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants