Skip to content

Conversation

@jimeh
Copy link
Owner

@jimeh jimeh commented Jun 11, 2025

Replace yaml.v3 with goccy/go-yaml, as the former is now unmaintained.

Also upgrade minimum Go version to 1.21.0 and update testify to v1.10.0.

Add support for configuring encoder options in YAML renderer to
provide more flexibility in YAML output formatting. Include new options
for sequence indentation and automatic integer conversion.

Implement support for both yaml.InterfaceMarshaler and
yaml.BytesMarshaler interfaces with appropriate test cases. Rename mock
implementation to clarify interface implementation.

@jimeh jimeh force-pushed the replace-gopkg-yaml-with-goccy-yaml branch 2 times, most recently from 3a6418e to f1a160e Compare June 11, 2025 02:54
@jimeh
Copy link
Owner Author

jimeh commented Jun 13, 2025

Tests are failing cause the the YAML encoder does not return errors from the io.Writer. I have submitted a PR to fix this here: goccy/go-yaml#761

@jimeh jimeh force-pushed the replace-gopkg-yaml-with-goccy-yaml branch from f1a160e to 2c737d2 Compare June 13, 2025 23:15
@jimeh jimeh requested a review from Copilot June 13, 2025 23:15
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request replaces the unmaintained yaml.v3 library with github.com/goccy/go-yaml while upgrading the minimum Go version and updating related dependencies and tests. Key changes include:

  • Renaming and refactoring mock types and test cases to support the new yaml.InterfaceMarshaler and yaml.BytesMarshaler interfaces.
  • Introducing encoder option support in the YAML renderer along with sequence indentation and auto integer conversion features.
  • Upgrading Go version and dependencies in go.mod and updating CI workflow accordingly.

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
yaml_test.go Updated tests and mock types to align with the new YAML library
yaml.go Integrated new encoder options and improved encoder usage
render_test.go Adjusted tests and message expectations to support new interface names
mise.toml Removed obsolete tool versions
go.mod Upgraded Go version and dependencies, including replacing yaml.v3
.github/workflows/ci.yml Updated CI workflow to reflect the new minimum Go version

yaml.go Outdated
Comment on lines 45 to 50
opts = append(opts, yaml.Indent(y.Indent))
}
if len(y.EncodeOptions) > 0 {
Copy link

Copilot AI Jun 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider clarifying the interaction between the YAML.Indent field and the EncodeOptions. When both are provided, ensure that duplicate or conflicting indent options do not lead to unpredictable behavior.

Suggested change
opts = append(opts, yaml.Indent(y.Indent))
}
if len(y.EncodeOptions) > 0 {
// Remove any existing yaml.Indent options from EncodeOptions
filteredOptions := make([]yaml.EncodeOption, 0, len(y.EncodeOptions))
for _, opt := range y.EncodeOptions {
if _, ok := opt.(yaml.IndentOption); !ok {
filteredOptions = append(filteredOptions, opt)
}
}
opts = append(opts, filteredOptions...)
opts = append(opts, yaml.Indent(y.Indent))
} else if len(y.EncodeOptions) > 0 {

Copilot uses AI. Check for mistakes.
require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Copy link

Copilot AI Jun 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The go.mod file still includes an indirect dependency on gopkg.in/yaml.v3 despite replacing it with github.com/goccy/go-yaml. Consider removing this dependency if it is no longer required.

Suggested change
gopkg.in/yaml.v3 v3.0.1 // indirect
# This line will be removed after running `go mod tidy`.

Copilot uses AI. Check for mistakes.
@jimeh
Copy link
Owner Author

jimeh commented Jun 21, 2025

bugbot run

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: YAML Render Method Causes Concurrency Issues

The YAML.Render method introduces two bugs. First, opts := YAMLDefaultEncoderOptions creates a slice sharing the underlying array with the global YAMLDefaultEncoderOptions. Appending to opts can modify the global variable if capacity allows, causing a race condition where default encoder options are unexpectedly altered for concurrent goroutines. Second, YAMLDefaultEncoderOptions already includes yaml.Indent(YAMLDefaultIndent). When y.Indent > 0, yaml.Indent(y.Indent) is appended to opts, resulting in two conflicting yaml.Indent options passed to the encoder. This changes the original behavior of y.Indent overriding the default and can cause unpredictable indentation.

yaml.go#L41-L49

go-render/yaml.go

Lines 41 to 49 in 2c737d2

func (y *YAML) Render(w io.Writer, v any) error {
opts := YAMLDefaultEncoderOptions
if y.Indent > 0 {
opts = append(opts, yaml.Indent(y.Indent))
}
if len(y.EncodeOptions) > 0 {
opts = append(opts, y.EncodeOptions...)
}

Fix in Cursor


BugBot free trial expires on July 22, 2025
You have used $0.00 of your $5.00 spend limit so far. Manage your spend limit in the Cursor dashboard.

Was this report helpful? Give feedback by reacting with 👍 or 👎

Replace yaml.v3 with goccy/go-yaml, as the former is now unmaintained.

Also upgrade minimum Go version to 1.21.0 and update testify to v1.10.0.

Add support for configuring encoder options in YAML renderer to
provide more flexibility in YAML output formatting. Include new options
for sequence indentation and automatic integer conversion.

Implement support for both yaml.InterfaceMarshaler and 
yaml.BytesMarshaler interfaces with appropriate test cases. Rename mock
implementation to clarify interface implementation.
@jimeh jimeh force-pushed the replace-gopkg-yaml-with-goccy-yaml branch from 2c737d2 to 6656062 Compare June 22, 2025 10:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants