Skip to content

hcl2tojson --with-meta flag accepted but produces no metadata #291

@kkozik-amplify

Description

@kkozik-amplify

Description

echo 'x = 1' | hcl2tojson - --with-meta
# → {"x": 1}
# Expected: {"x": 1, "__start_line__": 1, "__end_line__": 1}

The --with-meta flag is accepted without error but the output contains no __start_line__ / __end_line__ keys.

Root Cause

The with_meta option is a stub that was never wired up during the v8 architecture overhaul:

  • cli/hcl_to_json.py defines the flag and passes it to SerializationOptions
  • hcl2/utils.py defines with_meta: bool = False on the dataclass ✓
  • No serialize() method in rules/base.py ever checks options.with_meta
  • The metadata (line, end_line, column, end_column) exists on every LarkRule._meta — it's just never written to the output dict
  • hcl2/const.py is missing START_LINE_KEY / END_LINE_KEY constants
  • Tests only verify the flag is accepted without error, not that output contains metadata

Expected Behavior

When --with-meta is passed, every attribute and block in the output dict should include __start_line__ and __end_line__ keys sourced from LarkRule._meta.

Workaround

Use hq --with-location which correctly provides line/column metadata.

Suggested Fix

Each serialize() method (AttributeRule, BlockRule, etc.) needs to check if options.with_meta: and inject __start_line__ / __end_line__ keys from self._meta. Add corresponding constants to hcl2/const.py.

Related: #130

Metadata

Metadata

Labels

bugSomething isn't workingclihcl2tojson, jsontohcl2, and hq CLIsinternal-testingFound during internal test runsserializationLarkElement IR to Python dict (forward path)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions