Skip to content

fix(format): re-emit the = scaling lock in cooklang source - #737

Merged
LeMyst merged 3 commits into
cooklang:mainfrom
drawmeanelephant:fix/702-scaling-lock-marker
Oct 17, 2026
Merged

LeMyst merged 3 commits into
cooklang:mainfrom
drawmeanelephant:fix/702-scaling-lock-marker

Conversation

@drawmeanelephant

Copy link
Copy Markdown
Contributor

Closes #702

ComponentFormatter never wrote =, so @egg{=2} round-tripped as @egg{2} and reparsed with scalable: true — scaling the formatted recipe ×10 gives 20 eggs instead of 2. The lock is now emitted for ingredient quantities that parsed non-scalable; cookware, timers and text values can't carry it without a parser warning, so those are left alone.

Test plan

  • new test a_locked_quantity_keeps_its_lock asserts the marker survives and reparse gives scalable: false
  • cargo test -p cooklang-format green
  • repro: Add @egg{=2} and @milk{100%ml}. round-trips verbatim

`ComponentFormatter` never wrote `=`, so `@egg{=2}` round-tripped as
`@egg{2}` and the quantity silently became scalable — scaling the
formatted recipe ×10 gives 20 eggs instead of 2. Emit the lock for
ingredient quantities that parsed as non-scalable; cookware, timers and
text values can't carry it without a parser warning.

Closes #702

@LeMyst LeMyst left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good to me. scalable == false on a non-text ingredient quantity can only come from a lock. Cookware and timers are never scaled, so leaving the lock off them loses nothing. A locked fraction now round-trips as @egg{=1/2%cup}.

  • The re-emitted lock makes the parser warn "Unnecessary scaling lock modifier" on parse-back, but that's a cooklang-rs bug: it warns on every lock, even a valid @egg{=2}. It isn't caused by this PR, and it may deserve an issue there.
  • Optional test: format at scale ×10 and check that {=2} is still there.

This conflicts with #736 in the if let Some(q) block (push =, then write_value) and in the tests, and with #735 in the tests. Also note that #755 currently refuses locked fractions, which this PR makes round-trip.


🤖 Analysis and recommendations made by Claude (Anthropic's AI assistant), posted on behalf of @LeMyst.

@drawmeanelephant

Copy link
Copy Markdown
Contributor Author

Added the ×10 test (a_locked_quantity_survives_scaling: @egg{=2} stays locked while @milk{100%ml} comes out {1000%ml}), and filed the spurious lock warning upstream as cooklang/cooklang-rs#135.

@drawmeanelephant
drawmeanelephant force-pushed the fix/702-scaling-lock-marker branch from 57d96fc to 6acedad Compare October 14, 2026 13:30
@LeMyst

LeMyst commented Oct 17, 2026

Copy link
Copy Markdown
Collaborator

Thanks. a_locked_quantity_survives_scaling (crates/format/src/cooklang_source.rs:540) covers the ×10 case: @egg{=2} stays locked while @milk{100%ml} becomes {1000%ml}. Thanks for filing cooklang/cooklang-rs#135 for the lock warning too. CI is green on 6acedad, so this looks good to merge.

For whoever merges second, there are two small conflicts in crates/format/src/cooklang_source.rs:


🤖 Analysis and recommendations made by Claude (Anthropic's AI assistant), posted on behalf of @LeMyst.

Resolves the conflict with #736 in crates/format/src/cooklang_source.rs:
write this PR's `=` lock first, then the value through #736's
write_value, and keep both PRs' tests.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01GYHHHngC4XZ4nfdgP4p3Pe
@LeMyst
LeMyst merged commit 6191ef7 into cooklang:main Oct 17, 2026
5 checks passed
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.

cooklang format drops the = scaling-lock marker

2 participants