Right now the YAML syntax is ambiguous for anchors and aliases.
The fact an anchor or alias name can contain a : leads to oddities.
For example, this is valid
---
a: &foo: 42
m:
- bar
- *foo:
It will result to this
It's uncommon, but why not after all. The YAML specification supports it.
But now, consider this:
---
a: &foo 42
m:
*foo: bar
What is it about ?
-
an alias and anchor named foo ?
So this
But then the valid YAML syntax for would be this:
---
a: &foo 42
m:
*foo : bar
With a space after *foo before the :, here it's because of the possible trailing : in alias name
Please note, that right now, yamllint:
- does not report using *foo: is ambiguous while it should/could, even if it's via a setting like "forbid ambiguous anchor name".
- would report there is an extra space after the *foo: while using *foo: bar is invalid in fact in YAML, as it means "the alias named foo: followed by the scalar bar".
-
an anchor named foo and alias named foo: (with trailing :)
Because then it would be this
which is invalid
This is unlikely to happen, so it proves it will occur 😄
I would prefer if yamllint could report that using an anchor with a trailing : as invalid, and report using an alias followed by a : in map is invalid.
cc @mikefarah @ingydotnet
I found this while taking a look at
Right now the YAML syntax is ambiguous for anchors and aliases.
The fact an anchor or alias name can contain a
:leads to oddities.For example, this is valid
It will result to this
It's uncommon, but why not after all. The YAML specification supports it.
But now, consider this:
What is it about ?
an alias and anchor named
foo?So this
But then the valid YAML syntax for would be this:
With a space after
*foobefore the:, here it's because of the possible trailing:in alias namePlease note, that right now, yamllint:
- does not report using
*foo:is ambiguous while it should/could, even if it's via a setting like "forbid ambiguous anchor name".- would report there is an extra space after the
*foo:while using*foo: baris invalid in fact in YAML, as it means "the alias namedfoo:followed by the scalar bar".an anchor named
fooand alias namedfoo:(with trailing:)Because then it would be this
which is invalid
This is unlikely to happen, so it proves it will occur 😄
I would prefer if yamllint could report that using an anchor with a trailing
:as invalid, and report using an alias followed by a:in map is invalid.cc @mikefarah @ingydotnet
I found this while taking a look at