Repository: casey/just
File: src/analyzer.rs (Rust)

Code before:
        }
        Setting::Shell(shell) => {
          assert!(settings.shell.is_none());
          settings.shell = Some(shell);
        }
        Setting::WindowsPowerShell(windows_powershell) => {
          settings.windows_powershell = windows_powershell;
        }
      }
    }

    let assignments = self.assignments;

    AssignmentResolver::resolve_assignments(&assignments)?;

    for recipe in recipes {
      if let Some(original) = self.recipes.get(recipe.name.lexeme()) {
        if settings.allow_duplicate_recipes {
            self.recipes.remove(recipe.name.lexeme());
        } else {
          return Err(recipe.name.token().error(DuplicateRecipe {
            recipe: original.name(),
            first: original.line_number(),
          }));
        }
      }
      self.recipes.insert(recipe);
    }

    let recipes = RecipeResolver::resolve_recipes(self.recipes, &assignments)?;

    for recipe in recipes.values() {
      for parameter in &recipe.parameters {
        if assignments.contains_key(parameter.name.lexeme()) {
          return Err(parameter.name.token().error(ParameterShadowsVariable {
            parameter: parameter.name.lexeme(),
          }));
        }
      }
    }

    let mut aliases = Table::new();
    while let Some(alias) = self.aliases.pop() {
      aliases.insert(Self::resolve_alias(&recipes, alias)?);
    }

    Ok(Justfile {
      warnings: ast.warnings,
      first: recipes
        .values()
        .fold(None, |accumulator, next| match accumulator {

Review comment (refactor):
Since insert will overwrite something already in the table, this can just be:

```suggestion
        if !settings.allow_duplicate_recipes {
          return Err(recipe.name.token().error(DuplicateRecipe {
            recipe: original.name(),
            first: original.line_number(),
          }));
        }
      }
```

Code after:
        }
        Setting::Shell(shell) => {
          assert!(settings.shell.is_none());
          settings.shell = Some(shell);
        }
        Setting::WindowsPowerShell(windows_powershell) => {
          settings.windows_powershell = windows_powershell;
        }
      }
    }

    let assignments = self.assignments;

    AssignmentResolver::resolve_assignments(&assignments)?;

    for recipe in recipes {
      if let Some(original) = self.recipes.get(recipe.name.lexeme()) {
        if !settings.allow_duplicate_recipes {
          return Err(recipe.name.token().error(DuplicateRecipe {
            recipe: original.name(),
            first: original.line_number(),
          }));
        }
      }
      self.recipes.insert(recipe);
    }

    let recipes = RecipeResolver::resolve_recipes(self.recipes, &assignments)?;

    for recipe in recipes.values() {
      for parameter in &recipe.parameters {
        if assignments.contains_key(parameter.name.lexeme()) {
          return Err(parameter.name.token().error(ParameterShadowsVariable {
            parameter: parameter.name.lexeme(),
          }));
        }
      }
    }

    let mut aliases = Table::new();
    while let Some(alias) = self.aliases.pop() {
      aliases.insert(Self::resolve_alias(&recipes, alias)?);
    }

    Ok(Justfile {
      warnings: ast.warnings,
      first: recipes
        .values()
        .fold(None, |accumulator, next| match accumulator {
          None => Some(Rc::clone(next)),
          Some(previous) => Some(if previous.line_number() < next.line_number() {