Vscode-yaml: Support for custom YAML tags

Created on 25 Mar 2018  路  14Comments  路  Source: redhat-developer/vscode-yaml

Some utilities extend YAML syntax with custom tags. For example JJB introduces "include" tags, http://jenkins-job-builder.readthedocs.io/en/latest/definition.html?highlight=!include-raw#module-jenkins_jobs.local_yaml

YAML linter fails on provided examples.
Eg here

- job:
  name: test-job-1
  builders:
    !include: include001.yaml.inc

it says unknown tag <!include:> at: '4,5'.

According to documentation, currently there is no way

  • to ignore some warnings, or
  • to extend YAML schema with additional tags.

But custom tags are language feature, see http://www.yaml.org/spec/1.2/spec.html#id2761292 , Example 2.24. Global Tags. This document causes errors too:

%TAG ! tag:clarkevans.com,2002:
--- !shape
  # Use the ! handle for presenting
  # tag:clarkevans.com,2002:circle
- !circle
  center: &ORIGIN {x: 73, y: 129}
  radius: 7
- !line
  start: *ORIGIN
  finish: { x: 89, y: 102 }
- !label
  start: *ORIGIN
  color: 0xFFEEBB
  text: Pretty vector drawing.

Could you implement this spec or add some workaround?

enhancement

Most helpful comment

Having the same issue db_url: !secret db_url when using secrets variables in home assistant.

All 14 comments

Facing the same problem for CloudFormation templates which have tags like !Ref, !GetAtt etc.

Currently as far as I can tell the underlying parser doesn't support custom tags. I'm not sure if that is something that could be easily added to that parser or if its worth changing parsers.

Having the same issue db_url: !secret db_url when using secrets variables in home assistant.

@JPinkney right, it has only built-in support for !include tag. Project also seems to be a bit small and lonely.
Can't you use https://github.com/nodeca/js-yaml as underlying parser? It seems to support custom tags. I'm just asking, not an expert in js and don't really now how stuff works in this extension.

@sanyer I'm going to look into it and compare a few of the options

@JPinkney cool, thanks :-)

I realized that the same problem is with Ansible playbooks. It has custom !vault tag for inlining encrypted secrets.

BTW, there is a plugin for atom https://atom.io/packages/linter-js-yaml where this option is supported.

Does js-yaml provide an AST? Last time I have checked there was only one YAML parser that provided AST. Without an AST we can not provide code assist.

There is a new one that provides an AST that I've been looking into. I haven't done a full evaluation yet but it could potentially help resolve this and https://github.com/redhat-developer/vscode-yaml/issues/75

@JPinkney awesome, great that there are suitable alternatives

Is this still being considered? I work with YAML which includes custom tags as well and my files show tons of errors that aren't real.

It will be added in the release tomorrow.

Added in 0.0.12 release.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rylnd picture rylnd  路  3Comments

remcohaszing picture remcohaszing  路  4Comments

hppsc1215 picture hppsc1215  路  7Comments

teresaejunior picture teresaejunior  路  4Comments

opsarno picture opsarno  路  5Comments