google / yamlfmt

An extensible command line tool or library to format yaml files.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Config option to reject anchors and aliases?

imjasonh opened this issue · comments

I'd like to be able to ensure a YAML document doesn't include any anchors or aliases: https://yaml.org/spec/1.2.2/#3222-anchors-and-aliases, e.g.:

definitions: 
  steps:
    - step: &build-test
        name: Build and test
        script:
          - mvn package
        artifacts:
          - target/**

pipelines:
  branches:
    develop:
      - step: *build-test
    main:
      - step: *build-test

(from here: https://support.atlassian.com/bitbucket-cloud/docs/yaml-anchors/)

It doesn't look like that's currently possible with this tool, but would you accept a PR to add it?

Practically speaking I think this would look like checking for Node.Kind == yaml.AliasNode, or Node.Anchor != "", defined in the Node type. The option would probably default to false for compatibility.

Thanks for your patience! I've been on leave.

This seems like a good feature. I wasn't aware of this use case. I would accept a PR, I think I may use it to inform another architecture adjustment I've been considering for a while, which would be a middle step that can accept yaml.v3's node representation. Haven't really decided how to do that yet. If you already have a PR I'd be happy to look it over, and probably merge it in while I figure out the best way to do that. (That way I can also make sure whatever adjustments I make match the test cases 😄)
If not, I'll begin working on this as my next issue.

This is in really good shape so I'm going to include it in the next release! Hoping it'll be out before the end of this week.