Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

versionCatalog() silently deletes standalone comments at section boundaries and EOF

已关闭
#3,048 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 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:

  1. between the final entry of one table and the next table header, or
  2. 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:

https://github.com/diffplug/spotless/blob/cd8b6e2b4532f6533bd78c0d0ffec8ee37cae0e6/lib/src/main/java/com/diffplug/spotless/toml/VersionCatalogStep.java#L127-L168

#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

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

diffplug/spotless 的其他 Issue

查看 diffplug/spotless 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。