undefined-template-option

disallow a ${templateOption:...} reference to an option not declared in devcontainer-template.json

Category
correctness
Applies to
template
Platforms
all

Why

Applying a Template replaces each “${templateOption:name}” with the value the user chose for the option of that name. A reference to an option that “options” does not declare is never prompted for, and the reference implementation substitutes the empty string for it, so a typo silently produces an empty value in the applied files instead of an error.

Bad

devcontainer-template.json

{
  "id": "dotnet",
  "version": "1.0.0",
  "name": "C# (.NET)",
  "options": {
    "imageVariant": {
      "type": "string",
      "proposals": ["8.0", "9.0"],
      "default": "9.0"
    }
  }
}

.devcontainer/devcontainer.json

{
  "image": "mcr.microsoft.com/devcontainers/dotnet:${templateOption:variant}"
}

Good

devcontainer-template.json

{
  "id": "dotnet",
  "version": "1.0.0",
  "name": "C# (.NET)",
  "options": {
    "imageVariant": {
      "type": "string",
      "proposals": ["8.0", "9.0"],
      "default": "9.0"
    }
  }
}

.devcontainer/devcontainer.json

{
  "image": "mcr.microsoft.com/devcontainers/dotnet:${templateOption:imageVariant}"
}

References