Bug Description
According to the Servings proposal document, Cooklang supports locking ingredient amounts to one value using =, so that these ingredients are not scaled when increasing or decreasing the recipe serving size. However any recipe that uses this locking feature causes tooling such as cooklang-cli and the Cooklang Playground to report an error. This is especially confusing for new users, since it makes it seem like this feature is unsupported or broken.
This issue was observed with cookcli 0.32.1 and version 57b2c62 of the Cooklang Playground.
Expected Result
A recipe containing ingredients with locked values such as @milk{=1%cup} does not cause an error to be reported by the cook doctor command.
Actual Result
A recipe containing ingredients with locked values such as @milk{=1%cup} causes the cook doctor command to report an error about the scaling lock modifier being unnecessary, and that the scaling lock has no effect.
Example
Steps to Reproduce
- Create a file named
test.cook with the following contents:
---
servings: 2
---
Add @milk{=1%cup} and mix until smooth.
- Run
cook doctor and notice that the following error is reported: Warning: Unnecessary scaling lock modifier.
- (Optional) Paste the contents of
test.cook into the Cooklang Playground and notice that the same error is reported:
Warning: Unnecessary scaling lock modifier
╭─[playground]
│
5 │ Add @milk{=1%cup} and mix until smooth.
┆ ┬
┆ │
┆ ╰──────────────────────────── this scaling lock has no effect
──╯
Possible Fix
Looking at the code in event_consumer.rs, the warning message comes from this part of the code:
|
// Warn if scaling lock is used unnecessarily (on non-ingredients or text values) |
|
if has_scaling_lock { |
|
let mut warning = warning!( |
|
"Unnecessary scaling lock modifier", |
|
label!(value.span(), "this scaling lock has no effect") |
|
); |
|
|
|
if !is_ingredient { |
|
warning.add_hint("Only ingredients can be scaled, scaling lock is not needed here"); |
|
} else if is_text { |
|
warning.add_hint("Text values cannot be scaled, scaling lock is not needed here"); |
|
} |
|
|
|
self.ctx.warn(warning); |
|
} |
This logic immediately creates a warning if a scaling lock is found, before checking whether the value is an ingredient or text (e.g. cookware). Updating the if-condition to something like the following would probably fix the issue (although perhaps there's a more elegant solution):
// Warn if scaling lock is used unnecessarily (on non-ingredients or text values)
-if has_scaling_lock {
+if has_scaling_lock && (!is_ingredient || is_text) {
let mut warning = warning!(
"Unnecessary scaling lock modifier",
label!(value.span(), "this scaling lock has no effect")
);
if !is_ingredient {
warning.add_hint("Only ingredients can be scaled, scaling lock is not needed here");
} else if is_text {
warning.add_hint("Text values cannot be scaled, scaling lock is not needed here");
}
self.ctx.warn(warning);
}
Bug Description
According to the Servings proposal document, Cooklang supports locking ingredient amounts to one value using
=, so that these ingredients are not scaled when increasing or decreasing the recipe serving size. However any recipe that uses this locking feature causes tooling such ascooklang-cliand the Cooklang Playground to report an error. This is especially confusing for new users, since it makes it seem like this feature is unsupported or broken.This issue was observed with
cookcli0.32.1and version57b2c62of the Cooklang Playground.Expected Result
A recipe containing ingredients with locked values such as
@milk{=1%cup}does not cause an error to be reported by thecook doctorcommand.Actual Result
A recipe containing ingredients with locked values such as
@milk{=1%cup}causes thecook doctorcommand to report an error about the scaling lock modifier being unnecessary, and that the scaling lock has no effect.Example
Steps to Reproduce
test.cookwith the following contents:cook doctorand notice that the following error is reported:Warning: Unnecessary scaling lock modifier.test.cookinto the Cooklang Playground and notice that the same error is reported:Warning: Unnecessary scaling lock modifier ╭─[playground] │ 5 │ Add @milk{=1%cup} and mix until smooth. ┆ ┬ ┆ │ ┆ ╰──────────────────────────── this scaling lock has no effect ──╯Possible Fix
Looking at the code in
event_consumer.rs, the warning message comes from this part of the code:cooklang-rs/src/analysis/event_consumer.rs
Lines 1038 to 1052 in 1a05061
This logic immediately creates a warning if a scaling lock is found, before checking whether the value is an ingredient or text (e.g. cookware). Updating the if-condition to something like the following would probably fix the issue (although perhaps there's a more elegant solution):