Skip to content

Commit 86d65b0

Browse files
authored
feat: Disable expandEmptyElements, to avoid empty body warnings (#2520)
2 parents 38989da + 694eb30 commit 86d65b0

File tree

4 files changed

+181
-2
lines changed

4 files changed

+181
-2
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
1616
* Use `palantir-java-format` as default formatter in `RemoveUnusedImportsStep`. ([#2541](https://github.com/diffplug/spotless/pull/2541))
1717
* scalafmt: enforce version consistency between the version configured in Spotless and the version declared in Scalafmt config file ([#2460](https://github.com/diffplug/spotless/issues/2460))
1818
### Fixed
19+
* `SortPom` disable expandEmptyElements, to avoid empty body warnings. ([#2520](https://github.com/diffplug/spotless/pull/2520))
1920
* Fix biome formatter for new major release 2.x of biome ([#2537](https://github.com/diffplug/spotless/pull/2537))
2021
* Make sure npm-based formatters use the correct `node_modules` directory when running in parallel. ([#2542](https://github.com/diffplug/spotless/pull/2542))
2122
### Changed

lib/src/main/java/com/diffplug/spotless/pom/SortPomCfg.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2021-2024 DiffPlug
2+
* Copyright 2021-2025 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -27,7 +27,7 @@ public class SortPomCfg implements Serializable {
2727

2828
public String lineSeparator = System.getProperty("line.separator");
2929

30-
public boolean expandEmptyElements = true;
30+
public boolean expandEmptyElements;
3131

3232
public boolean spaceBeforeCloseEmptyElement = false;
3333

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
/*
2+
* Copyright 2025 DiffPlug
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.diffplug.spotless.pom;
17+
18+
import static org.assertj.core.api.Assertions.assertThat;
19+
20+
import org.junit.jupiter.api.Test;
21+
22+
class SortPomCfgTest {
23+
24+
@Test
25+
void testDefaultValues() {
26+
SortPomCfg cfg = new SortPomCfg();
27+
28+
// Test default values using AssertJ
29+
assertThat(cfg.version).isEqualTo("4.0.0");
30+
assertThat(cfg.encoding).isEqualTo("UTF-8");
31+
assertThat(cfg.lineSeparator).isEqualTo(System.getProperty("line.separator"));
32+
assertThat(cfg.expandEmptyElements).isFalse();
33+
assertThat(cfg.spaceBeforeCloseEmptyElement).isFalse();
34+
assertThat(cfg.keepBlankLines).isTrue();
35+
assertThat(cfg.endWithNewline).isTrue();
36+
assertThat(cfg.nrOfIndentSpace).isEqualTo(2);
37+
assertThat(cfg.indentBlankLines).isFalse();
38+
assertThat(cfg.indentSchemaLocation).isFalse();
39+
assertThat(cfg.indentAttribute).isNull();
40+
assertThat(cfg.predefinedSortOrder).isEqualTo("recommended_2008_06");
41+
assertThat(cfg.quiet).isFalse();
42+
assertThat(cfg.sortOrderFile).isNull();
43+
assertThat(cfg.sortDependencies).isNull();
44+
assertThat(cfg.sortDependencyManagement).isNull();
45+
assertThat(cfg.sortDependencyExclusions).isNull();
46+
assertThat(cfg.sortPlugins).isNull();
47+
assertThat(cfg.sortProperties).isFalse();
48+
assertThat(cfg.sortModules).isFalse();
49+
assertThat(cfg.sortExecutions).isFalse();
50+
}
51+
52+
@Test
53+
void testFieldSetters() {
54+
SortPomCfg cfg = new SortPomCfg();
55+
56+
// Set all fields
57+
cfg.version = "4.1.0";
58+
cfg.encoding = "ISO-8859-1";
59+
cfg.lineSeparator = "\n";
60+
cfg.expandEmptyElements = true;
61+
cfg.spaceBeforeCloseEmptyElement = true;
62+
cfg.keepBlankLines = false;
63+
cfg.endWithNewline = false;
64+
cfg.nrOfIndentSpace = 4;
65+
cfg.indentBlankLines = true;
66+
cfg.indentSchemaLocation = true;
67+
cfg.indentAttribute = "attribute";
68+
cfg.predefinedSortOrder = "custom";
69+
cfg.quiet = true;
70+
cfg.sortOrderFile = "sortOrder.xml";
71+
cfg.sortDependencies = "groupId,artifactId";
72+
cfg.sortDependencyManagement = "scope,groupId";
73+
cfg.sortDependencyExclusions = "artifactId";
74+
cfg.sortPlugins = "groupId";
75+
cfg.sortProperties = true;
76+
cfg.sortModules = true;
77+
cfg.sortExecutions = true;
78+
79+
// Verify all set values with AssertJ
80+
assertThat(cfg.version).isEqualTo("4.1.0");
81+
assertThat(cfg.encoding).isEqualTo("ISO-8859-1");
82+
assertThat(cfg.lineSeparator).isEqualTo("\n");
83+
assertThat(cfg.expandEmptyElements).isTrue();
84+
assertThat(cfg.spaceBeforeCloseEmptyElement).isTrue();
85+
assertThat(cfg.keepBlankLines).isFalse();
86+
assertThat(cfg.endWithNewline).isFalse();
87+
assertThat(cfg.nrOfIndentSpace).isEqualTo(4);
88+
assertThat(cfg.indentBlankLines).isTrue();
89+
assertThat(cfg.indentSchemaLocation).isTrue();
90+
assertThat(cfg.indentAttribute).isEqualTo("attribute");
91+
assertThat(cfg.predefinedSortOrder).isEqualTo("custom");
92+
assertThat(cfg.quiet).isTrue();
93+
assertThat(cfg.sortOrderFile).isEqualTo("sortOrder.xml");
94+
assertThat(cfg.sortDependencies).isEqualTo("groupId,artifactId");
95+
assertThat(cfg.sortDependencyManagement).isEqualTo("scope,groupId");
96+
assertThat(cfg.sortDependencyExclusions).isEqualTo("artifactId");
97+
assertThat(cfg.sortPlugins).isEqualTo("groupId");
98+
assertThat(cfg.sortProperties).isTrue();
99+
assertThat(cfg.sortModules).isTrue();
100+
assertThat(cfg.sortExecutions).isTrue();
101+
}
102+
103+
@Test
104+
void testNullHandling() {
105+
SortPomCfg cfg = new SortPomCfg();
106+
107+
// Set nullable fields to null
108+
cfg.version = null;
109+
cfg.encoding = null;
110+
cfg.lineSeparator = null;
111+
cfg.indentAttribute = null;
112+
cfg.predefinedSortOrder = null;
113+
cfg.sortOrderFile = null;
114+
cfg.sortDependencies = null;
115+
cfg.sortDependencyManagement = null;
116+
cfg.sortDependencyExclusions = null;
117+
cfg.sortPlugins = null;
118+
119+
// Verify null values with AssertJ
120+
assertThat(cfg.version).isNull();
121+
assertThat(cfg.encoding).isNull();
122+
assertThat(cfg.lineSeparator).isNull();
123+
assertThat(cfg.indentAttribute).isNull();
124+
assertThat(cfg.predefinedSortOrder).isNull();
125+
assertThat(cfg.sortOrderFile).isNull();
126+
assertThat(cfg.sortDependencies).isNull();
127+
assertThat(cfg.sortDependencyManagement).isNull();
128+
assertThat(cfg.sortDependencyExclusions).isNull();
129+
assertThat(cfg.sortPlugins).isNull();
130+
}
131+
132+
@Test
133+
void testBooleanFieldsEdgeCases() {
134+
SortPomCfg cfg = new SortPomCfg();
135+
136+
// Toggle all boolean fields
137+
cfg.expandEmptyElements = !cfg.expandEmptyElements;
138+
cfg.spaceBeforeCloseEmptyElement = !cfg.spaceBeforeCloseEmptyElement;
139+
cfg.keepBlankLines = !cfg.keepBlankLines;
140+
cfg.endWithNewline = !cfg.endWithNewline;
141+
cfg.indentBlankLines = !cfg.indentBlankLines;
142+
cfg.indentSchemaLocation = !cfg.indentSchemaLocation;
143+
cfg.quiet = !cfg.quiet;
144+
cfg.sortProperties = !cfg.sortProperties;
145+
cfg.sortModules = !cfg.sortModules;
146+
cfg.sortExecutions = !cfg.sortExecutions;
147+
148+
// Verify all boolean fields are toggled
149+
assertThat(cfg.expandEmptyElements).isTrue();
150+
assertThat(cfg.spaceBeforeCloseEmptyElement).isTrue();
151+
assertThat(cfg.keepBlankLines).isFalse();
152+
assertThat(cfg.endWithNewline).isFalse();
153+
assertThat(cfg.indentBlankLines).isTrue();
154+
assertThat(cfg.indentSchemaLocation).isTrue();
155+
assertThat(cfg.quiet).isTrue();
156+
assertThat(cfg.sortProperties).isTrue();
157+
assertThat(cfg.sortModules).isTrue();
158+
assertThat(cfg.sortExecutions).isTrue();
159+
}
160+
161+
@Test
162+
void testNumericFieldEdgeCases() {
163+
SortPomCfg cfg = new SortPomCfg();
164+
165+
// Test minimum value
166+
cfg.nrOfIndentSpace = 0;
167+
assertThat(cfg.nrOfIndentSpace).isZero();
168+
169+
// Test negative value
170+
cfg.nrOfIndentSpace = -1;
171+
assertThat(cfg.nrOfIndentSpace).isNegative();
172+
173+
// Test large value
174+
cfg.nrOfIndentSpace = Integer.MAX_VALUE;
175+
assertThat(cfg.nrOfIndentSpace).isEqualTo(Integer.MAX_VALUE);
176+
}
177+
}

plugin-maven/CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
77
* Support for `idea` ([#2020](https://github.com/diffplug/spotless/pull/2020), [#2535](https://github.com/diffplug/spotless/pull/2535))
88
* Add support for removing wildcard imports via `removeWildcardImports` step. ([#2517](https://github.com/diffplug/spotless/pull/2517))
99
### Fixed
10+
* `SortPom` disable expandEmptyElements, to avoid empty body warnings. ([#2520](https://github.com/diffplug/spotless/pull/2520))
1011
* Fix biome formatter for new major release 2.x of biome ([#2537](https://github.com/diffplug/spotless/pull/2537))
1112
* Make sure npm-based formatters use the correct `node_modules` directory when running in parallel. ([#2542](https://github.com/diffplug/spotless/pull/2542))
1213
### Changed

0 commit comments

Comments
 (0)