Skip to content

fix: highlight invalid property values and array items - #173

Open
falko-apheris wants to merge 1 commit into
jsonnext:mainfrom
falko-apheris:fix/diagnostic-value-ranges
Open

falko-apheris wants to merge 1 commit into
jsonnext:mainfrom
falko-apheris:fix/diagnostic-value-ranges

Conversation

@falko-apheris

Copy link
Copy Markdown

Summary

Fixes #158 and fixes #165.

Schema validation detects these errors, but their diagnostic ranges can point to the start of the document, a colon, or a neighboring token instead of the invalid value.

  • Register value-only JSON pointers for primitive, object, and nested-array items.
  • Find property values by node type rather than a fixed sibling offset. This handles both the locked JSON grammar and newer grammars that expose the colon as a named node, as well as JSON5 comments.
  • Preserve property key/value ranges when traversing object values, rather than overwriting the property's range with its child object.
  • Make key ranges optional for values without keys. Preserve the existing behavior of highlighting the containing value for missing required properties, and keep the root-level diagnostic fallback unchanged.
  • Add a patch changeset and 45 regression cases covering JSON, JSON5, YAML flow/block sequences, nested arrays, object-valued properties, escaped JSON Pointer paths, and unfinished properties.

For example, an integer-array schema applied to {"values": [0, "invalid", 2]} now highlights "invalid", rather than producing a zero-length diagnostic at the document start.

Related work

This overlaps with #142 by @tbrockman and follows the same value-only-pointer approach for array items. This PR is a focused fix against current main, adding grammar-independent property-value lookup and regression coverage while retaining the existing missing-required-property highlighting behavior. It does not change dependencies, lockfiles, validation rules, or error messages.

Verification

  • pnpm run test --run --silent --no-file-parallelism: 177 tests passed.
  • Repeated the full suite with @lezer/json@1.0.3 temporarily substituted for locked 1.0.1: 177 tests passed. Restored the original dependency afterward; no dependency changes are included.
  • pnpm run tsc and pnpm run build passed.
  • Prettier and all pre-commit hooks passed (test workers limited to one).
  • Browser verification in the existing demo: JSON, JSON5, and YAML all underline the invalid property value 42 and array item false; no JavaScript page errors.

Existing tooling notes: I used pnpm 9.15.9 for the frozen install because packageManager specifies pnpm 8.6.6 but the checked-in lockfile is version 9. Parallel test execution intermittently produced incomplete syntax-tree/range failures on this machine; I reproduced that on untouched main as well. The serial suite passes. Those unrelated tooling issues are not changed here.

Browser proof

The screenshot uses the demo's existing package.json schema and generic inputs, with no response overrides or changes to the demo:

Invalid property and array values are underlined in JSON, JSON5, and YAML

@changeset-bot

changeset-bot Bot commented Sep 21, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 5cb6c1f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
codemirror-json-schema Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@netlify

netlify Bot commented Sep 21, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for codemirror-json-schema ready!

Name Link
🔨 Latest commit 5cb6c1f
🔍 Latest deploy log https://app.netlify.com/projects/codemirror-json-schema/deploys/6ab1226e4e45880008bf80c4
😎 Deploy Preview https://deploy-preview-173--codemirror-json-schema.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@falko-apheris

Copy link
Copy Markdown
Author

Hello there, any updates on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error marker highlights colon instead of invalid value Incorrect Error Marker Position for Type Mismatch in Nested Array Items

1 participant