This Bugzilla instance is deprecated, and most Eclipse projects now use GitHub or Eclipse GitLab. Please see the deprecation plan for details.
Bug 501252 - XML formatter can't do simple attribute wrapping at line width
Summary: XML formatter can't do simple attribute wrapping at line width
Status: RESOLVED FIXED
Alias: None
Product: WTP Source Editing
Classification: WebTools
Component: wst.xml (show other bugs)
Version: 3.9 (Oxygen)   Edit
Hardware: PC Windows NT
: P3 minor with 1 vote (vote)
Target Milestone: 3.9.3   Edit
Assignee: Nitin Dahyabhai CLA
QA Contact: Nick Sandonato CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-09-12 10:03 EDT by Garret Wilson CLA
Modified: 2023-01-07 13:54 EST (History)
4 users (show)

See Also:
nsand.dev: review+


Attachments
proposed modification (7.38 KB, patch)
2017-08-28 23:47 EDT, Nitin Dahyabhai CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Garret Wilson CLA 2016-09-12 10:03:15 EDT
I have the following XML line (perhaps one of the most common lines of XML in all of Java development)---the opening tag of the root element of a Maven POM:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

In the XML formatter I set the line width to 160. I reformat and get... the exact same thing. No wrapping whatsoever:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

I go into the settings and turn on "Split multiple attributes each on a new line" and reformat. I get this:

<project
	xmlns="http://maven.apache.org/POM/4.0.0"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

That's not correct either! I don't want _everything_ wrapped. I just want it wrapped at 160 columns, like this:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
		xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

If I had a line of Java code like this in an interface:

	public void foo(@Nonnull final int foo, @Nonnull final int bar, @Nonnull final int example, @Nonnull final int test, @Nonnull final int foobar, @Nonnull final int fooExample, @Nonnull final int barExample);

I wouldn't want to have to choose between that one lone line, or every parameter wrapped:

	public void foo(@Nonnull final int foo, @Nonnull final int bar, @Nonnull final int example, @Nonnull final int test, @Nonnull final int foobar, @Nonnull final int fooExample, @Nonnull final int barExample);

	public void foo(
			@Nonnull final int foo,
			@Nonnull final int bar,
			@Nonnull final int example,
			@Nonnull final int test,
			@Nonnull final int foobar,
			@Nonnull final int fooExample,
			@Nonnull final int barExample);

Of course not. I would expect wrapping at 160 columns as I requested:

	public void foo(@Nonnull final int foo, @Nonnull final int bar, @Nonnull final int example, @Nonnull final int test, @Nonnull final int foobar,
			@Nonnull final int fooExample, @Nonnull final int barExample);

And that's what I get in the Java formatter! But I don't get that in the XML formatter; I have to chose between a long line and every-attribute-wrapped.

Please fix the XML formatter to only wrap an attribute at or before the number of columns, as I requested in the settings, and similar to how the Java formatter works.
Comment 1 Garret Wilson CLA 2016-09-12 10:07:04 EDT
Even worse, if I manually split at 160 columns:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
		xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

Then the formatter _joins_ the lines---even though I have the settings to wrap at 160 columns! So in this case the formatter modifies my XML to make it _less_ compliant with the formatting configuration.
Comment 2 Garret Wilson CLA 2016-09-12 10:09:13 EDT
P.S. I could swear this is new behavior, because I have a lot of Maven POMs that are nicely formatted, but I'm not sure. Anyway, this current formatter behavior is going to screw up so many files and add unnecessary Git commits.
Comment 3 Nitin Dahyabhai CLA 2016-09-13 18:47:47 EDT
1) Which version of WTP is this?
2) The xsi:schemaLocation value contains a line feed. Changing that would change the value.
Comment 4 Garret Wilson CLA 2017-08-27 23:52:43 EDT
> The xsi:schemaLocation value contains a line feed. Changing that would change the value.

Actually not really. Are you familiar with XML attribute normalization? This would not change the parsed DOM at all. See https://www.w3.org/TR/REC-xml/#AVNormalize . So this would only be a source code syntax change --- which is the whole point of XML source code formatting.

Again, I'm pretty sure this is new behavior. Didn't it work before?
Comment 5 Garret Wilson CLA 2017-08-27 23:54:30 EDT
And nobody has told me why it will _join_ lines, forcing a line that is longer than the limit!
Comment 6 Garret Wilson CLA 2017-08-27 23:55:54 EDT
> Which version of WTP is this?

I'm just using the default Eclipse 4.7.0 J2EE package installation.
Comment 7 Nitin Dahyabhai CLA 2017-08-28 23:47:13 EDT
Created attachment 270002 [details]
proposed modification

(In reply to Garret Wilson from comment #5)
> And nobody has told me why it will _join_ lines, forcing a line that is
> longer than the limit!

Of all possibilities, a typo in the source that does the calculation.
Comment 8 Nick Sandonato CLA 2017-09-02 09:22:02 EDT
Path looks good to me.
Comment 9 Nitin Dahyabhai CLA 2017-11-07 09:05:43 EST
Committed to master.
Comment 10 Nitin Dahyabhai CLA 2017-12-17 15:30:14 EST
Moving to 3.9.3 since didn't make into the 3.9.2 builds.
Comment 11 Marcin Slusarczyk CLA 2022-04-02 06:28:01 EDT
I still experience faulty behavior on:
Eclipse XML Editors and Tools Version: 3.25.0.v202201160258
Eclipse Platform Version: 4.23.0.v20220308-0722 Build id: I20220308-0310

Please reopen the bug.
Comment 12 Olivier Cailloux CLA 2023-01-07 12:51:48 EST
I confirm that this problem happens again with Eclipse Java with Wild Web Developer tools. Please re-open.
Comment 13 Nitin Dahyabhai CLA 2023-01-07 13:54:07 EST
(In reply to Olivier Cailloux from comment #12)
> I confirm that this problem happens again with Eclipse Java with Wild Web
> Developer tools. Please re-open.

This is not where Wild Web Developer, nor where LemminX, bugs get reported. The POM editor is now based on https://github.com/eclipse/lemminx-maven.