feat: add JSON schema validation for devcontainer files#63
Closed
nozaq wants to merge 7 commits into
Closed
Conversation
…chema Validate devcontainer.json and Feature files against the vendored, embedded official Dev Container schemas, catching the class of problems the rules do not: misspelled or unknown property names, wrong value types, and out-of-range enum values. - New schema package: embeds the spec base/main/feature schemas plus the VS Code and Codespaces extension schemas, compiles them fully offline, and maps validation errors to source positions with "did you mean" suggestions for misspelled properties. - The -schema flag and "schema" config member select the variant (main/base/off); main is the default. Findings are always errors under the schema-validation ID, independent of rule severities and ignore comments. Validation runs on the file as written, before merging and substitution. - decolint -version now reports the vendored schema revision; the schema-sync workflow and "make update-schemas" keep the vendored copies current. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DpyKDWbaKADMJ3kkyWKuN6
…lidation-xhgzq9 # Conflicts: # cmd/decolint/main.go # cmd/decolint/main_test.go # cmd/decolint/opts.go
golangci-lint's wrapcheck flagged the error from schema.ParseVariant as returned unwrapped. Wrap it the way the surrounding code wraps cross-package errors, and phrase the package's own message like parseFormat's so the two compose without repeating "schema". Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DpyKDWbaKADMJ3kkyWKuN6
The schema sync job only failed when the vendored schemas fell behind upstream, leaving the update itself to be done by hand. Have it open a pull request with the refreshed files instead, using the housekeeper app token the way the templates repository's release workflow does. The job's own token now only needs to read the repository, since every write goes through the app token. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DpyKDWbaKADMJ3kkyWKuN6
Every main package now lives under cmd, so the schema updater sits alongside the decolint binary rather than in internal. Only "make update-schemas" referred to it; the released artifacts are unaffected, since build and install name ./cmd/decolint explicitly. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DpyKDWbaKADMJ3kkyWKuN6
The schema updater recorded the upstream commits on every run, so the sync workflow would have raised a pull request whenever either branch moved — and microsoft/vscode moves many times a day without touching a schema. It now compares what it downloads against what is vendored and writes nothing unless a schema itself differs. The sources were also marshaled from a map, whose order json/v2 leaves unspecified, so the file was reordered on every run and looked changed either way. Marshal them deterministically, as the config file already does for the same reason. REVISIONS.json is regenerated here, so the committed file matches what the updater produces: same schema contents, ordered sources, and the commit those contents currently come from. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DpyKDWbaKADMJ3kkyWKuN6
The updateschemas binary landed in the previous commit; it is build output, not source. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DpyKDWbaKADMJ3kkyWKuN6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds comprehensive JSON schema validation for devcontainer configuration files, complementing the existing rule-based linting engine.
Summary
Decolint now validates devcontainer.json, devcontainer-template.json, and devcontainer-feature.json files against the official Dev Container JSON schemas. The schemas are vendored from the upstream devcontainers/spec and microsoft/vscode repositories and embedded in the binary, requiring no network access.
Key Changes
New
schemapackage: Provides schema validation viaValidate()function that checks file structure, property names, value types, enums, and unknown propertiesVendored schemas: Added five official JSON schemas to
schema/data/:devContainer.base.schema.json- core spec schemadevContainer.schema.json- main schema composing base + extensionsdevContainerFeature.schema.json- feature metadata schemadevContainer.codespaces.schema.json- GitHub Codespaces extensionsdevContainer.vscode.schema.json- VS Code extensionsREVISIONS.json- tracks upstream commit SHAsSchema update tooling: Added
internal/updateschemascommand to refresh vendored schemas from upstream repositories, with automated CI workflow (schema-sync.yml) to detect stale schemasIntegration with linter:
-schemaflag andschemaconfig file member to select validation variantTesting: Comprehensive test coverage for schema validation, error message generation, property name suggestions, and variant parsing
Implementation Details
https://claude.ai/code/session_01DpyKDWbaKADMJ3kkyWKuN6