Skip to content

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

Closed

Description

@kwin

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.

Activity

  1. nedtwigg commented on Sep 27, 2024

    @nedtwigg
    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?

  2. kwin commented on Sep 28, 2024

    @kwin
    ContributorAuthor

    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.

  3. nedtwigg commented on Oct 2, 2024

    @nedtwigg
    Member

    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.

  4. kwin commented on Oct 3, 2024

    @kwin
    ContributorAuthor

    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.

  5. changed the title [-]Add option to normalize line ending prior checking or ignore during check[/-] [+]Add option to preserve line ending during check/formatting[/+] on Oct 3, 2024
  6. added 2 commits that reference this issue on Nov 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions