{"id":20148207,"url":"https://github.com/chainguard-dev/yam","last_synced_at":"2025-10-24T17:03:20.752Z","repository":{"id":65339024,"uuid":"587847096","full_name":"chainguard-dev/yam","owner":"chainguard-dev","description":"A sweet little formatter for YAML","archived":false,"fork":false,"pushed_at":"2025-03-18T14:43:46.000Z","size":226,"stargazers_count":22,"open_issues_count":5,"forks_count":11,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-18T15:45:00.041Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chainguard-dev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-01-11T18:17:42.000Z","updated_at":"2025-03-18T14:43:50.000Z","dependencies_parsed_at":"2023-02-13T01:16:21.932Z","dependency_job_id":"4e6d71c9-8476-4115-98b0-89f86940c767","html_url":"https://github.com/chainguard-dev/yam","commit_stats":null,"previous_names":[],"tags_count":27,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chainguard-dev%2Fyam","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chainguard-dev%2Fyam/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chainguard-dev%2Fyam/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chainguard-dev%2Fyam/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chainguard-dev","download_url":"https://codeload.github.com/chainguard-dev/yam/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248103900,"owners_count":21048244,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-13T22:35:22.413Z","updated_at":"2025-10-24T17:03:20.663Z","avatar_url":"https://github.com/chainguard-dev.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# yam 🍠\n\nA sweet little formatter for YAML\n\n## Installation\n\n```shell\ngo install github.com/chainguard-dev/yam@latest\n```\n\n## Usage\n\n### Format...\n\nTo update file contents to match your formatting configuration, just specify one or more YAML files.\n\n```shell\nyam a.yaml b.yaml\n```\n\nYou can also specify directories with YAML files in them. (Yam doesn't recurse through directories in directories.)\n\n```shell\nyam ./dir-with-some-yamls\n```\n\nAnd you can format files in the current working directory if you don't pass any arguments:\n\n```shell\nyam\n```\n\n### Lint...\n\nTo **_lint_** files instead of formatting them, just add `--lint` to the command. With this flag, Yam doesn't make any changes to your files, but it will exit `1` if any files don't match your formatting configuration.\n\n```shell\nyam a.yaml --lint\n```\n\nWhen linting, if Yam finds any files that don't pass the lint check, it will output a diff of what it got vs. what it expected to see.\n\n## Formatting/Linting Options\n\n### Gap Lines\n\nTo expect a gap (empty line) in between child elements of a given node, just pass a `yq`-style path to the node, using `--gap`. You can use this flag as many times as needed.\n\n```shell\nyam a.yaml --gap '.'\n```\n\n```shell\nyam a.yaml --gap '.foo.bar'\n```\n\n```shell\nyam a.yaml --gap '.people[].address'\n```\n\n```shell\nyam a.yaml --gap '.recipes[0].ingredients'\n```\n\n```shell\nyam a.yaml --gap '.types.*.inputs'\n```\n\n### Indentation\n\nYou can also set the indent size (number of spaces) using `--indent`. Yam uses 2-space indentation by default.\n\n```shell\nyam a.yaml --indent 4\n```\n\n### Sorting sequences\n\nYou can also sort sequences so that for example you get alphabetized packages\nlist using `--sort` where `--sort` takes in a `yq`-style path to the node that\nshould be sorted.\n\n```shell\nyam a.yaml --sort .packages\n```\n\n**Note** This is only meant to be used for scalars, behavior for objects is not\nsupported.\n\n### Using a config file\n\nYam will also look for a `.yam.yaml` file in the current working directory as a source of configuration. Using a config file is optional. CLI flag values take priority over config file values. The config file can be used to configure `indent` and `gap` values only.\n\nExample `.yam.yaml`:\n\n```yaml\nindent: 4   # Defaults to 2\n\ngap:        # Defaults to none\n- \".\"\n- \".users\"\n```\n\n## Yam's Encoder\n\nYam has a special YAML encoder it uses to handle formatting as it writes out YAML bytes. This encoder is configurable.\n\nYam bases its encoder on the YAML encoder from https://github.com/go-yaml/yaml, and uses this library's `yaml.Node` type as the input to encoding operations.\n\nThis means you're able to decode data using https://github.com/go-yaml/yaml, modify data as needed, and then encode the `yaml.Node` using **yam's encoder** instead. This is nifty if you want to write YAML data that's correctly formatted from the beginning.\n\nFor example, before:\n\n```go\nimport (\n    // ...\n    \"gopkg.in/yaml.v3\"\n)\n\nfunc someFunction(myData yaml.Node, w io.Writer) {\n    enc := yaml.NewEncoder(w)\n\n    // use the encoder!\n\t_ = enc.Encode(myData)\n}\n```\n\nAnd after:\n\n```go\nimport (\n    // ...\n    \"github.com/chainguard-dev/yam/pkg/yam/formatted\"\n)\n\nfunc someFunction(myData yaml.Node, w io.Writer) {\n    enc := formatted.NewEncoder(w)\n\n    // use the encoder!\n    _ = enc.Encode(myData)\n}\n```\n\n### Configuring the encoder\n\nYam's encoder has chainable methods that can be used for configuring its options.\n\nFor example:\n\n```go\nenc := formatted.NewEncoder(w).SetIndent(2).SetGapExpressions(\".\", \".users\")\n```\n\n#### Configuring the encoder with `.yam.yaml`\n\nYou can also tell the encoder to behave similarly to the `yam` command, in that a `.yam.yaml` is automatically read if available.\n\n```go\nenc := formatted.NewEncoder(w).AutomaticConfig()\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchainguard-dev%2Fyam","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchainguard-dev%2Fyam","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchainguard-dev%2Fyam/lists"}