Skip to content

Commit 87596f8

Browse files
committed
handle inline comments after semicolons
Signed-off-by: Suvrat Acharya <suvrat1629@gmail.com>
1 parent ec2d333 commit 87596f8

2 files changed

Lines changed: 36 additions & 1 deletion

File tree

src/main/kotlin/org/hiero/gradle/spotless/SortModuleInfoRequiresStep.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,11 @@ class SortModuleInfoRequiresStep {
6767
continue
6868
}
6969
current.add(line)
70-
if (line.trimEnd().endsWith(";")) {
70+
if (
71+
line.trimEnd().endsWith(";") ||
72+
(line.contains(";") &&
73+
line.substringAfter(";").trim().startsWith("//"))
74+
) {
7175
flushCurrent()
7276
}
7377
}

src/test/kotlin/org/hiero/gradle/test/QualityGateTest.kt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,37 @@ class QualityGateTest {
210210
assertThat(result.task(":qualityGate")?.outcome).isEqualTo(TaskOutcome.SUCCESS)
211211
}
212212

213+
@Test
214+
fun `spotlessApply preserves inline comments in module-info directives`() {
215+
val p = GradleProject().withMinimalStructure()
216+
p.moduleBuildFile("""plugins { id("org.hiero.gradle.module.library") }""")
217+
val moduleInfo =
218+
p.moduleInfoFile(
219+
"""
220+
module org.hiero.product.module.a {
221+
requires transitive javax.inject;
222+
requires transitive java.compiler; // javax.annotation.processing.Generated
223+
}
224+
"""
225+
.trimIndent()
226+
)
227+
228+
val result = p.run("spotlessApply")
229+
230+
assertThat(moduleInfo)
231+
.hasContent(
232+
"""
233+
// SPDX-License-Identifier: Apache-2.0
234+
module org.hiero.product.module.a {
235+
requires transitive java.compiler; // javax.annotation.processing.Generated
236+
requires transitive javax.inject;
237+
}
238+
"""
239+
.trimIndent()
240+
)
241+
assertThat(result.task(":spotlessApply")?.outcome).isEqualTo(TaskOutcome.SUCCESS)
242+
}
243+
213244
@Test
214245
fun `spotlessApply formats rust files`() {
215246
val p = GradleProject().withMinimalStructure()

0 commit comments

Comments
 (0)