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

Code before:
  }

  pub(crate) fn enabled(&self) -> bool {
    let windows = self.attributes.contains(&Attribute::Windows);
    let linux = self.attributes.contains(&Attribute::Linux);
    let macos = self.attributes.contains(&Attribute::Macos);
    let unix = self.attributes.contains(&Attribute::Unix);

    (!windows && !linux && !macos && !unix)
      || (cfg!(target_os = "windows") && windows)
      || (cfg!(target_os = "linux") && (linux || unix))
      || (cfg!(target_os = "macos") && (macos || unix))
      || (cfg!(windows) && windows)
      || (cfg!(unix) && unix)
  }

  fn print_exit_message(&self) -> bool {
    !self.attributes.contains(&Attribute::NoExitMessage)
  }

  fn working_directory<'a>(&'a self, context: &'a ExecutionContext) -> Option<PathBuf> {
    if !self.change_directory() {
      return None;
    }

    let working_dir = self
      .attributes
      .iter()
      .filter_map(|attribute| match attribute {
        Attribute::WorkingDirectory(dir) => Some(dir),
        _ => None,
      })
      .last();

    Some(
      working_dir
        .map(|dir| context.working_directory().join(dir.raw))
        .unwrap_or(context.working_directory()),
    )
  }

  fn no_quiet(&self) -> bool {
    self.attributes.contains(&Attribute::NoQuiet)
  }

  pub(crate) fn run<'run>(
    &self,
    context: &ExecutionContext<'src, 'run>,
    scope: &Scope<'src, 'run>,
    positional: &[String],
    is_dependency: bool,

Review comment (security):
I think this is better implemented as a for loop:

```rust
let working_directory = context.working_directory();

for attribute in self.attributes {
  if let Attribute::WorkingDirectory(dir) = attribute {
    return Some(working_directory.join(dir.cooked);
  }
}

Some(working_directory)
```

Also note the use of `cooked`, which is the contents of the string literal after processing escape sequences.

Code after:
  pub(crate) fn enabled(&self) -> bool {
    let windows = self.attributes.contains(&Attribute::Windows);
    let linux = self.attributes.contains(&Attribute::Linux);
    let macos = self.attributes.contains(&Attribute::Macos);
    let unix = self.attributes.contains(&Attribute::Unix);

    (!windows && !linux && !macos && !unix)
      || (cfg!(target_os = "windows") && windows)
      || (cfg!(target_os = "linux") && (linux || unix))
      || (cfg!(target_os = "macos") && (macos || unix))
      || (cfg!(windows) && windows)
      || (cfg!(unix) && unix)
  }

  fn print_exit_message(&self) -> bool {
    !self.attributes.contains(&Attribute::NoExitMessage)
  }

  fn working_directory<'a>(&'a self, context: &'a ExecutionContext) -> Option<PathBuf> {
    if !self.change_directory() {
      return None;
    }

    let working_directory = context.working_directory();

    for attribute in &self.attributes {
      if let Attribute::WorkingDirectory(dir) = attribute {
        return Some(working_directory.join(&dir.cooked));
      }
    }

    Some(working_directory)
  }

  fn no_quiet(&self) -> bool {
    self.attributes.contains(&Attribute::NoQuiet)
  }

  pub(crate) fn run<'run>(
    &self,
    context: &ExecutionContext<'src, 'run>,
    scope: &Scope<'src, 'run>,
    positional: &[String],
    is_dependency: bool,
  ) -> RunResult<'src, ()> {
    let color = context.config.color.stderr().banner();
    let prefix = color.prefix();
    let suffix = color.suffix();

    if context.config.verbosity.loquacious() {
      eprintln!("{prefix}===> Running recipe `{}`...{suffix}", self.name);