Skip to content

feat: Added support for commented JSON; simplified instrumentation exports#2

Merged
regularkevvv merged 3 commits intomainfrom
feat/commented-json-and-instrumentation-simplified
Jan 23, 2026
Merged

feat: Added support for commented JSON; simplified instrumentation exports#2
regularkevvv merged 3 commits intomainfrom
feat/commented-json-and-instrumentation-simplified

Conversation

@regularkevvv
Copy link
Copy Markdown
Collaborator

@regularkevvv regularkevvv commented Jan 22, 2026

Summary

  • Add allow_comments option to JSON parser for JSONC-style files with // and /* */ comments
  • Remove deprecated instrument() function - use TemplateSpec instead which handles instrumentation internally
  • Simplify public API by hiding internal utilities

Changes

JSON Comments Support

rendered.as_json(allow_comments=True)
rendered.as_json_blocks(allow_comments=True)

Uses a state-tracking parser that correctly handles:

  • Comment-like patterns inside strings (URLs, // in text)
  • Escaped quotes (\")
  • Escaped backslashes (\\) including edge case "foo\\" (string ending with backslash)

Removed from Public API

  • instrument() - TemplateSpec handles this internally
  • create_instrumentation(), load_template_with_markers(), transform_markers()
  • AnchorIndex, TraceRecorder, MarkerTransform

Still Public

  • has_markers(), discover_markers() - useful for CI/tooling
  • TestInstrumentation, ProductionInstrumentation - for type hints

Test Plan

  • All 516 tests pass
  • 23 edge case tests for comment stripping
  • Lint passes

Copilot AI review requested due to automatic review settings January 22, 2026 06:18
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds support for parsing JSON with C-style comments (JSONC) and simplifies the public API by removing the deprecated instrument() function and other internal utilities.

Changes:

  • Added allow_comments parameter to as_json() and as_json_blocks() methods to support JSONC-style files with // and /* */ comments
  • Removed instrument() function from public API; callers should use TemplateSpec which handles instrumentation internally, or use create_instrumentation() + manual env setup
  • Removed internal utilities (create_instrumentation, load_template_with_markers, transform_markers, AnchorIndex, TraceRecorder, MarkerTransform) from public exports

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
jinjatest/parsers/json_parser.py Added allow_comments parameter and comment-stripping logic using regex patterns
jinjatest/rendered.py Added allow_comments parameter to as_json() and as_json_blocks() methods
jinjatest/init.py Removed internal instrumentation and marker utilities from public exports
jinjatest/instrumentation.py Removed instrument() function (deprecated in favor of TemplateSpec or manual setup)
jinjatest/spec.py Updated to use create_instrumentation() directly instead of instrument()
jinjatest/markers.py Updated docstring example to show manual instrumentation setup
tests/test_parsers.py Added comprehensive tests for JSON comment parsing feature
tests/test_basic.py Added tests for as_json(allow_comments=True) and updated imports
tests/test_fenced_blocks.py Added test for as_json_blocks(allow_comments=True)
tests/test_markers.py Updated to import create_instrumentation from jinjatest.instrumentation
tests/test_instrumentation.py Removed tests for deprecated instrument() function
tests/test_imports.py Updated to reflect removed exports
README.md Updated documentation to show allow_comments usage and removed instrument() examples
Makefile Renamed target from test-coverage to test-cov

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@regularkevvv regularkevvv merged commit 0af91e1 into main Jan 23, 2026
6 checks passed
@regularkevvv regularkevvv deleted the feat/commented-json-and-instrumentation-simplified branch January 23, 2026 01:18
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.

2 participants