Skip to content

Doctor command raises a warning when encountering locked ingredient amounts #97

Description

@lucasmelin

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

Scaling lock error bug

Steps to Reproduce

  1. Create a file named test.cook with the following contents:
    ---
    servings: 2
    ---
    
    Add @milk{=1%cup} and mix until smooth.
  2. Run cook doctor and notice that the following error is reported: Warning: Unnecessary scaling lock modifier.
  3. (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);
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions