eslint-plugin-yml icon indicating copy to clipboard operation
eslint-plugin-yml copied to clipboard

[improvement request] detect template strings

Open gajus opened this issue 4 years ago • 2 comments

Many templating frameworks that interpolate yaml depend on {{ foo }} syntax to define directives, e.g.

apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  finalizers:
    - resources-finalizer.argocd.argoproj.io
  name: contra-web-review-storybook-$DEPLOYMENT_SLUG
  namespace: argocd
spec:
  destination:
    namespace: default
    server: {{ .Values.spec.destination.server | quote }}

In these cases, eslint-plugin-yml will produce the following errors:

/Users/gajus/Documents/dev/contra/contra-web-app/bin/contra-web-app-review-template.yaml
  11:14  error  Empty mapping values are forbidden  yml/no-empty-mapping-value
  11:14  error  The key must be a string            yml/require-string-key
  11:15  error  Empty mapping values are forbidden  yml/no-empty-mapping-value

It would be desirable to have an option to recognize this special syntax and treat it as a string literal.

gajus avatar Nov 18 '21 02:11 gajus

I think it's good if it's possible, but I think it's difficult if there is no parser that can parse it well.

ota-meshi avatar Nov 18 '21 04:11 ota-meshi

This specific problem is a non-issue b/c I can replace

server: {{ .Values.spec.destination.server | quote }}

with

server: '{{ .Values.spec.destination.server }}'

However, the one that I cannot figure out a workaround for is this one:

apiVersion: v1
kind: Service
metadata:
  labels:
    {{- include "app.resource_labels" . | indent 4}}
  name: '{{.Release.Name}}'
spec:
  ports:
    - name: industry-report-2021-web-app
      port: 80
      protocol: TCP
      targetPort: 80
  selector:
    {{- include "app.selector_labels" . | indent 4}}

gajus avatar Jan 05 '22 00:01 gajus