question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Spaces in self-closing tags

See original GitHub issue

I notice that sortpom will insert spaces in self-closing empty tags, <likeThis />. Self-closing tags are are not common in Maven but we have a few in some plugin configurations, like <requireUpperBoundDeps />.

While I don’t feel strongly either way about this format, it’s different than IntelliJ’s default and I was curious if this was a conscious choice. It causes some noise for us when developers use IntelliJ’s auto-format and then our build system reverts it with sortpom, potentially complaining about unexpected working tree changes. We have lots of non-pom XML files already formatted <withNoSpace/> so I am reluctant to change the IntelliJ XML format settings.

I didn’t see a way to configure this behavior in sortpom. Would you consider adding the ability to configure this behavior to use no space instead? (Or did I miss it and it’s already supported?)

Another alternative, if you don’t want to add a new parameter, would be for sortpom to allow either one or zero spaces to remain unchanged. Then at least it wouldn’t fight with IntelliJ, even if the pom might end up with a mixed format.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
AndyFWealthfrontcommented, Jul 3, 2020

Thanks again. I’ve already updated to this version in my company’s parent pom and set the flag 😃

1reaction
AndyFWealthfrontcommented, Jul 1, 2020

Thanks for the suggestion. We have bound sortpom:sort to the validate phase with createBackupFile=false, which doesn’t guarantee that the pom will always be sorted, but developers are running mvn validate often enough that the sorted pom gets committed pretty soon if anyone introduces some incorrect formatting. This doesn’t leave room for special cases but we haven’t found that to be a problem.

I find that this mostly achieves the goal of “all our poms look the same” without causing any headaches for developers who already have to deal with picky build failures from the checkstyle and enforcer plugins.

If I decided that the poms were still not being sorted often enough, rather than push it back on the devs with a build failure, I’d probably add a step to our build system to automatically commit the sortpom changes to the side branch! How’s that for an opinionated linter 😃 “Oh I see you did it wrong, here let me change that for you, you’re welcome!”

Read more comments on GitHub >

github_iconTop Results From Across the Web

Space Before Closing Slash? - html - Stack Overflow
The space just makes the tags more readable. I am a big proponent of formatting for more readable code. Little ...
Read more >
Why do you require space before closing tag slash?
It's very discouraging to type in what you perceive to be correct code and get no details about what's wrong with it when...
Read more >
Space in front of slash of self-closing tag - 2. Trados Studio
This space is breaking the import in the native application. The workaround is to manually fix it by find and replace, but it's...
Read more >
Avoid space before slash of self closing Xml element - MSDN
Question. Save method introduces the space before slash of self closing element, i.e. . NET Xml serializer always adds space, but is there...
Read more >
Feature request: trim whitespace from self-closing tags #806
In printing the meta tag, in PPrintTag, this is the code that ADDS the space... if ( (xmlOut || xhtmlOut) && (node->type == ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found