Commit Graph

42 Commits

Author SHA1 Message Date
Copilot
2927a28283
TOML encoder: prefer readable table sections over inline tables (#2649)
* Initial plan

* Fix TOML encoder to prefer readable table sections over inline tables

When converting from YAML/JSON to TOML, the encoder now always uses
readable TOML table section syntax ([section]) instead of compact inline
hash table syntax (key = { ... }), which better matches TOML's goal as
a human-focused configuration format.

Changes:
- decoder_toml.go: Mark inline TOML tables with FlowStyle so round-trips
  can be distinguished from YAML flow mappings
- encoder_toml.go:
  - encodeTopLevelEntry: use FlowStyle check instead of EncodeSeparate to
    decide inline vs table section (all block mappings now become tables)
  - encodeSeparateMapping: count FlowStyle children as attributes; use
    recursive encodeSeparateMapping for nested non-flow mappings
  - encodeMappingBodyWithPath: emit non-flow child mappings as sub-table
    sections instead of inline tables
- toml_test.go: add encode (YAML→TOML) test scenarios, update roundtrip
  expectations for inline tables (now expanded to table sections)

Agent-Logs-Url: https://github.com/mikefarah/yq/sessions/4824a219-6d5e-42e7-bca1-a8a277bf8c6a

Co-authored-by: mikefarah <1151925+mikefarah@users.noreply.github.com>

* Fix TOML roundtrip: use TomlInline flag instead of FlowStyle to preserve inline tables

FlowStyle affected YAML decode output (causing inline tables to appear as
YAML flow mappings). Replace it with a new TOML-specific TomlInline bool
on CandidateNode that:
- Is set by the TOML decoder for inline tables (not FlowStyle)
- Is copied by UpdateAttributesFrom so it survives DeeplyAssign merges
- Is checked by the TOML encoder alongside FlowStyle (for YAML flow maps)
- Has no effect on the YAML encoder, preserving existing TOML→YAML output

TOML roundtrip tests are restored to their original expected values (inline
tables stay inline, table sections stay as sections).

Agent-Logs-Url: https://github.com/mikefarah/yq/sessions/f59bdf62-6d16-4664-991b-38eb87c9d81c

Co-authored-by: mikefarah <1151925+mikefarah@users.noreply.github.com>

* Refactor EncodeSeparate+TomlInline into a single EncodeHint enum

Agent-Logs-Url: https://github.com/mikefarah/yq/sessions/24db9a8f-601d-4ccf-ada7-129ed3226bb6

Co-authored-by: mikefarah <1151925+mikefarah@users.noreply.github.com>

* Fix stale comment in hasStructuralChildren

Agent-Logs-Url: https://github.com/mikefarah/yq/sessions/24db9a8f-601d-4ccf-ada7-129ed3226bb6

Co-authored-by: mikefarah <1151925+mikefarah@users.noreply.github.com>

* Remove unused hasStructuralChildren method from tomlEncoder

Agent-Logs-Url: https://github.com/mikefarah/yq/sessions/2c234b77-28e9-4995-ba6f-9d213ec551a0

Co-authored-by: mikefarah <1151925+mikefarah@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: mikefarah <1151925+mikefarah@users.noreply.github.com>
2026-04-12 18:36:43 +10:00
Copilot
7d8d3ab902
Replace gopkg.in/op/go-logging.v1 with log/slog (#2635)
* Initial plan

* Replace gopkg.in/op/go-logging.v1 with log/slog

Co-authored-by: mikefarah <1151925+mikefarah@users.noreply.github.com>
Agent-Logs-Url: https://github.com/mikefarah/yq/sessions/aa9c12f4-21b9-4633-9868-6b56585b247f

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: mikefarah <1151925+mikefarah@users.noreply.github.com>
2026-03-26 20:41:54 +11:00
Mike Farah
6a965bc39a Bumping golint 2026-03-21 09:25:31 +11:00
Mike Farah
b8d90fd574
Update pkg/yqlib/candidate_node.go
Co-authored-by: ccoVeille <3875889+ccoVeille@users.noreply.github.com>
2025-12-20 15:05:03 +11:00
Mike Farah
5f9bf8d241 wip toml encoder 2025-12-14 19:03:54 +11:00
Mike Farah
f4fd8c585a Better roundtriping of HCL 2025-12-08 21:09:21 +11:00
Mike Farah
23a7b173bf Fixing merge anchor key order 2025-07-19 15:27:44 +10:00
Mike Farah
8e731ac13c Added "debug-node-info" flag for inspecting yq AST 2025-07-15 21:35:54 +10:00
Antoine Deschênes
b15ce77cad fix: correct key order after add, flatten, keys, sort, reverse and shuffle
Signed-off-by: Antoine Deschênes <antoine.deschenes@linux.com>
2025-06-07 21:04:26 +10:00
Mike Farah
20b5129120 Updating golanglint 2025-05-03 16:34:21 +10:00
Mike Farah
f202d06d82 sort_by works on maps 2025-01-22 14:36:50 +11:00
Mike Farah
730f240d24 Fixed to_entries and del bug #1886 2023-11-30 14:04:54 +11:00
Mike Farah
3d64bdadc1 Fixes issue when update against self #1869 2023-11-18 12:19:27 +11:00
Mike Farah
13d1bbb45f
Generic ast (#1829)
Remove dependency on yaml.Node for internal AST representation. Yaml decoder is now just another decoder.
2023-10-18 12:11:53 +11:00
-pthread -Wall
05ad1dad90
Fix typos (#1798) 2023-09-26 14:18:18 +10:00
Mike Farah
b4ca184108 Added new "c" flag to clobber custom tags when needed 2022-08-29 15:38:21 +10:00
Mike Farah
8d3be1a23c Length (and some other operators) should not include head/foot comments #1231 2022-05-31 16:28:53 +10:00
Mike Farah
6bce23d9c2 Improved handling of trailing document comments 2022-05-25 10:54:03 +10:00
Christoph Stäbler
dee592eb3b
Fix typo (#1222) 2022-05-24 18:18:27 +10:00
Mike Farah
ea66a73f43 Fixed sort dropping head comment #1181 2022-04-14 12:19:15 +10:00
Mike Farah
ff047d0748 Fixes #1123 2022-02-27 11:39:31 +11:00
Mike Farah
665f6b0267 Fixed self assigned issue #1107 2022-02-20 14:29:52 +11:00
Mike Farah
c3d815998a Auto style when adding to empty maps/arrays 2022-01-27 09:58:13 +11:00
Mike Farah
a6c79f3410 Multiply, substract with custom types 2022-01-22 16:12:59 +11:00
Matthieu MOREL
59752fb36d
enable more linters (#1043)
* enable revive linter

* enable gochecknoinits linter

* enable unconvert linter

* enable unparam linter

* enable asciicheck linter

* enable depguard linter

* enable nakedret linter

* enable megacheck linter

* enable nolintlint linter

* enable predeclared linter

* Update go.yml

* Update go.yml
2021-12-21 09:30:08 +11:00
Mike Farah
8b04d972f3 Improved error message 2021-12-05 10:58:26 +11:00
Mike Farah
dba41ffed7 Assignment op no longer clobbers anchor (#1029) 2021-12-03 09:23:24 +11:00
Mike Farah
b44fecdfa5 Added key operator 2021-11-24 09:57:35 +11:00
Mike Farah
d912d7d178 wip 2021-11-14 10:59:50 +11:00
Mike Farah
b1e64a0d80 Fixed newline handling when decoding/encoding 2021-10-22 14:53:39 +11:00
Mike Farah
c8630fe4f3 Fixes delete issue #793 2021-04-25 12:05:56 +10:00
Mike Farah
21a9e506cb Fixed merge comments 2021-03-19 12:54:03 +11:00
Mike Farah
c4c8e5e7b0 Preserve comments on map keys 2021-02-11 10:58:40 +11:00
Mike Farah
429c3ca65b Fixed merge dropping anchors 2021-02-11 10:58:40 +11:00
Mike Farah
76bd1896e9 wip 2021-02-11 10:58:40 +11:00
Mike Farah
55712afea6 Merge now copies anchor names 2021-02-11 10:58:40 +11:00
Mike Farah
7518dac99c Fixed creation of candidateNode in operators to include file metadata 2021-02-11 10:58:40 +11:00
Mike Farah
5aff50a345 Fixed updating yaml from other files 2021-02-11 10:58:40 +11:00
Mike Farah
98e8b3479f Fixed nested array splat path 2020-12-25 12:49:05 +11:00
Mike Farah
4e385a1b93 get file wip 2020-11-20 15:50:15 +11:00
Mike Farah
af39fc737d Fixed linting 2020-11-13 14:07:11 +11:00
Mike Farah
b1f139c965 refactored 2020-11-04 10:48:43 +11:00