Ekryd / sortpom

Maven plugin that helps the user sort pom.xml.
https://github.com/Ekryd/sortpom/wiki/
BSD 3-Clause "New" or "Revised" License
334 stars 178 forks source link

Add configuration for newline at the end of file #399

Closed zabetak closed 6 months ago

zabetak commented 8 months ago

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 commented 8 months ago

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

Ekryd commented 8 months ago

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 commented 8 months ago

🤦 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.

https://github.com/diffplug/spotless/issues/2002

Ekryd commented 7 months ago

Well, it is actually not rolled out yet

zabetak commented 7 months ago

Many thanks @Ekryd !

Ekryd commented 7 months ago

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