versionCatalog() silently deletes standalone comments at section boundaries and EOF
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 78/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- java
- 领域
- build-system
调研方向
从 lib/src/main/java/com/diffplug/spotless/toml/VersionCatalogStep.java 开始,重点查看 parseSections() 及其对 pendingComments 的处理。使用通过 StepHarness 调用 VersionCatalogStep.create() 的本地 JUnit 测试,重现 section 边界和 EOF 情况。当两个位置的独立注释在格式化后都能保留且没有错误或数据丢失时,即表示完成。
由索引模型根据 Issue 内容生成。
描述
Summary
versionCatalog() silently deletes standalone comments when they are either:
- between the final entry of one table and the next table header, or
- after the final entry at end of file.
The formatting task succeeds, so these comments are removed without an error or lint. This reproduces with the released Spotless Gradle plugin 8.10.2 and at commit cd8b6e2b4532f6533bd78c0d0ffec8ee37cae0e6 (the merge commit for #3042).
Environment
- Gradle: 9.7.1
- Spotless Gradle plugin: 8.10.2
- Also reproduced at commit:
cd8b6e2b4532f6533bd78c0d0ffec8ee37cae0e6(the merge commit for #3042) - OS: Windows 11 10.0 amd64
- JVM: 21.0.8
Spotless configuration
plugins {
id 'com.diffplug.spotless' version '8.10.2'
}
spotless {
toml {
target 'gradle/libs.versions.toml'
versionCatalog()
}
}
Input
gradle/libs.versions.toml:
[versions]
zoo = "1.0"
# keep this trailing comment
[libraries]
foo = { module = "g:a", version.ref = "zoo" }
# keep this final comment
Steps to reproduce
./gradlew spotlessApply --stacktrace
Actual output file
[versions]
zoo = "1.0"
[libraries]
foo = { module = "g:a", version.ref = "zoo" }
Both comments are removed.
Expected output
Both comments should be preserved. Their exact attachment to the preceding table or following header is less important than avoiding data loss.
Console output
There is no error or lint. The task reports success:
> Task :spotlessToml
> Task :spotlessTomlApply
> Task :spotlessApply
BUILD SUCCESSFUL in 20s
2 actionable tasks: 2 executed
The released-plugin reproduction above was run as a minimal Gradle project using version 8.10.2. The commit-level reproduction was verified separately with local JUnit tests which call VersionCatalogStep.create() through StepHarness using the same section-boundary and EOF inputs; it was not run through a source-built Gradle plugin.
Suspected cause
VersionCatalogStep.parseSections() stores standalone comments in pendingComments, but only attaches them when a later entry is parsed. A new table header clears pendingComments, and pending comments are not flushed at EOF:
#3042 fixed other comment/quote-related data-loss cases, but these section-boundary and EOF cases remain reproducible at commit cd8b6e2b4532f6533bd78c0d0ffec8ee37cae0e6 after that change.
- 主要语言
- Java
- 星标
- 5.7k
- 派生
- 560
- 平均合并
- 1 天 13 小时
- 30 天内合并 PR
- 43
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
diffplug/spotless 的其他 Issue
-
难度 5/5 一周以上 新手友好度 15/100
-
难度 5/5 一周以上 新手友好度 35/100
-
难度 3/5 1-2 天 新手友好度 66/100
-
难度 3/5 1-2 天 新手友好度 68/100
-
难度 4/5 3-5 天 新手友好度 52/100
查看 diffplug/spotless 的全部 Issue
相似的 Issue
-
area/plugin
难度 2/5 1-3 小时 新手友好度 75/100
kestra-io/plugin-kestra#190 ·
-
难度 2/5 1-3 小时 新手友好度 70/100
google-ai-edge/LiteRT-LM#3739 ·
-
bug
难度 2/5 1-3 小时 新手友好度 75/100
-
难度 2/5 1-3 小时 新手友好度 75/100
integra-team-red/meet-map#249 ·
-
[Studio][Bug] Cancelled create-user dialog keeps the password and admin switch for the next attempt 未关闭
难度 2/5 1-3 小时 新手友好度 75/100
apache/rocketmq-dashboard#5064 ·