openrewrite / openrewrite/rewrite

Xml Style - continuationIndent for attributes should align to tag name width

Open
#4,152 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Java
Stars
3.7k
Forks
570
Avg merge
13h 12m
Merged PRs (30d)
261

Description

What problem are you trying to solve?

Consider a small pom like this:

<?xml version="1.0" encoding="UTF-8"?>
<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">
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.sample</groupId>
  <artifactId>sample</artifactId>
  <version>1.0.0</version>
</project>

Observe the indentation (four spaces) of line 3.

If you pass a file like this through XML AutoFormat, you'll get that kind of indentation: continuation indents are 4 spaces by default.
But, if you run IntelliJ's autoformat, then it will indent like this:

<?xml version="1.0" encoding="UTF-8"?>
<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">
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.sample</groupId>
  <artifactId>sample</artifactId>
  <version>1.0.0</version>
</project>

On line 3, the content has been indented to 9 spaces, aligning with the first attributes of the line above after the tag name.

Describe the solution you'd like

Would be neat if there was an Xml Style / autoformat logic which supports this, and perhaps that should be the default style.

Have you considered any alternatives or workarounds?

Do nothing

Additional context

This indentation heuristic feels a bit unique? Not sure if implementing this would make a mess of the existing Autoformat / Style designs / interfaces.

Are you interested in contributing this feature to OpenRewrite?

I might, but, not a big priority. This might be a decent "first issue"?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the XML Style and AutoFormat logic responsible for continuation indentation, then read how the current four-space setting is applied to attributes. Done means supporting alignment to the tag name width, with the intended behavior reflected in the XML formatting design or default style.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.