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 configuration for newline at the end of file #399

Closed
zabetak opened this issue Jan 4, 2024 · 6 comments · Fixed by #403
Closed

Add configuration for newline at the end of file #399

zabetak opened this issue Jan 4, 2024 · 6 comments · Fixed by #403
Labels
enhancement released This is now part of the plugin

Comments

@zabetak
Copy link

zabetak commented Jan 4, 2024

Currently the plugin enforces the presence of a new line at the end of file; if the new line is not there it will be added by the sort phase. This may or may not be desirable thus usually formatting plugins leave the decision to the user (e.g., spotless provides endWithNewline config).

Ideally the presence of new line at the end of file should be configurable. For my use-case it would be also acceptable if the new line is not added at all by this plugin since if necessary I could achieve the same effect with other means (i.e., spotless).

@Ekryd
Copy link
Owner

Ekryd commented Jan 8, 2024

I can have a look and see it this can be fixed

@Ekryd
Copy link
Owner

Ekryd commented Jan 15, 2024

This can be implemented in PatchedXMLWriter:

  @Override
  public void write(Document doc) throws IOException {
        writeDeclaration();

        if (doc.getDocType() != null) {
            indent();
            writeDocType(doc.getDocType());
        }

        for (int i = 0, size = doc.nodeCount(); i < size; i++) {
            Node node = doc.node(i);
            writeNode(node);
        }

        // This is the line break at the end
        writePrintln();
  }

First, I need to ask: Does this issue cause problems for you? And how in that case?

@Ekryd
Copy link
Owner

Ekryd commented Jan 16, 2024

🤦 I just realised that spotless is actually using my plugin to process the pom-files. I'll contact them and ask if there are general settings for endWithNewline that I can support.

diffplug/spotless#2002

@Ekryd Ekryd linked a pull request Feb 19, 2024 that will close this issue
@Ekryd
Copy link
Owner

Ekryd commented Feb 19, 2024

Well, it is actually not rolled out yet

@Ekryd Ekryd reopened this Feb 19, 2024
@zabetak
Copy link
Author

zabetak commented Feb 20, 2024

Many thanks @Ekryd !

@Ekryd
Copy link
Owner

Ekryd commented Feb 20, 2024

Released version 3.4.0 with support for the new parameter endWithNewline. Please try it out

@Ekryd Ekryd closed this as completed Mar 9, 2024
@Ekryd Ekryd added the released This is now part of the plugin label Mar 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement released This is now part of the plugin
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants