Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace YAML parsers #1663

Open
suzuki-shunsuke opened this issue Feb 24, 2023 · 3 comments
Open

Replace YAML parsers #1663

suzuki-shunsuke opened this issue Feb 24, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@suzuki-shunsuke
Copy link
Member

There are three packages.

We couldn't use gopkg.in/yaml.v3 because gopkg.in/yaml.v3 didn't have Git tags.
But currently gopkg.in/yaml.v3 has tags, so we can use gopkg.in/yaml.v3 safely.

Replace goccy/go-yaml to gopkg.in/yaml.v3 partially

We use goccy/go-yaml for the following purposes.

  1. Patch YAML: gopkg.in/yaml.v3 also supports this feature
  2. IndentSequence: Only goccy/go-yaml supports this feature

Regarding IndentSequence, we still use goccy/go-yaml because only goccy/go-yaml supports this feature.

But regarding patching, maybe we can use gopkg.in/yaml.v3 instead of goccy/go-yaml.
I haven't patch YAML using gopkg.in/yaml.v3, so I have to verify it.

goccy/go-yaml has some issues.

  1. aqua g -i ignores the indent of registries when packages: is empty #585
  2. aqua g -i removes new lines #584
  3. Exec performance regression #582

Replace gopkg.in/yaml.v2 to gopkg.in/yaml.v3

We use gopkg.in/yaml.v2 instead of gopkg.in/yaml.v3 because gopkg.in/yaml.v3 couldn't parse YAML which has duplicated keys.
aqua should allow invalid YAML as much as possible, so we couldn't use gopkg.in/yaml.v3.

But I reconsider that we can use gopkg.in/yaml.v3 mainly and use gopkg.in/yaml.v2 only when gopkg.in/yaml.v3 can't parse YAML.

@suzuki-shunsuke
Copy link
Member Author

@suzuki-shunsuke
Copy link
Member Author

suzuki-shunsuke commented Feb 25, 2023

How do we keep indent by yaml.v3?

https://go.dev/play/p/TubU0SPmY69

package main

import (
	"log"
	"os"

	"gopkg.in/yaml.v3"
)

func main() {
	if err := core(); err != nil {
		log.Fatal(err)
	}
}

const data = `
---
packages:
- name: cli/[email protected]
`

func core() error {
	var cfg yaml.Node
	if err := yaml.Unmarshal([]byte(data), &cfg); err != nil {
		return err
	}
	if err := yaml.NewEncoder(os.Stdout).Encode(&cfg); err != nil {
		return err
	}
	return nil
}

Result: Indent was changed.

packages:
    - name: cli/[email protected]

I found issues.

@suzuki-shunsuke suzuki-shunsuke moved this from Todo to Backlog in main Feb 25, 2023
@github-project-automation github-project-automation bot moved this from Backlog to Done in main Apr 21, 2023
@suzuki-shunsuke
Copy link
Member Author

gopkg.in/yaml.v3 has

@suzuki-shunsuke suzuki-shunsuke moved this from Done to Backlog in main Apr 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
No open projects
Status: Backlog
Development

No branches or pull requests

1 participant