Repository: denoland/deno
File: cli/tools/fmt.rs (Rust)

Code before:
    if l.starts_with("}") {
      continue;
    }
    let mut chars = l.chars();
    // drop the indentation
    for _ in 0..config.indent_width {
      chars.next();
    }
    buf.push(chars.as_str());
  }
  Some(buf.join("\n").to_string())
}

/// Formats the embedded HTML code blocks in JavaScript and TypeScript.
fn format_embedded_html(
  text: &str,
  config: &dprint_plugin_typescript::configuration::Configuration,
) -> Option<String> {
  use markup_fmt::config;
  let options = config::FormatOptions {
    layout: config::LayoutOptions {
      indent_width: config.indent_width as usize,
      use_tabs: config.use_tabs,
      ..Default::default()
    },
    ..Default::default()
  };
  let Ok(text) = markup_fmt::format_text(
    text,
    markup_fmt::Language::Html,
    &options,
    |code, _| Ok::<_, std::convert::Infallible>(code.into()),
  ) else {
    return None;
  };
  Some(text.to_string())
}

/// Formats the embedded SQL code blocks in JavaScript and TypeScript.
fn format_embedded_sql(
  text: &str,
  config: &dprint_plugin_typescript::configuration::Configuration,
) -> Option<String> {
  Some(format_sql_text(text, config.use_tabs, config.indent_width))
}

fn format_sql_text(text: &str, use_tabs: bool, indent_width: u8) -> String {
  let mut text = sqlformat::format(
    text,
    &sqlformat::QueryParams::None,
    &sqlformat::FormatOptions {

Review comment (suggestion):
I think we should avoid using `...Default::default()` here and instead set the defaults explicitly. Otherwise the default could change in the plugins and that could break us (same above).

Code after:
      single_line_block_threshold: None,
      keyframe_selector_notation: None,
      attr_value_quotes: config::AttrValueQuotes::Always,
      prefer_single_line: false,
      selectors_prefer_single_line: None,
      function_args_prefer_single_line: None,
      sass_content_at_rule_prefer_single_line: None,
      sass_include_at_rule_prefer_single_line: None,
      sass_map_prefer_single_line: None,
      sass_module_config_prefer_single_line: None,
      sass_params_prefer_single_line: None,
      less_import_options_prefer_single_line: None,
      less_mixin_args_prefer_single_line: None,
      less_mixin_params_prefer_single_line: None,
      single_line_top_level_declarations: false,
      selector_override_comment_directive: "malva-selector-override".into(),
      ignore_comment_directive: "malva-ignore".into(),
      ignore_file_comment_directive: "malva-ignore-file".into(),
    },
  };
  // Wraps the text in a css block of `a { ... }`
  // to make it valid css (scss)
  let Ok(text) = malva::format_text(
    &format!("a{{\n{}\n}}", text),
    malva::Syntax::Scss,
    &options,
  ) else {
    return None;
  };
  let mut buf = vec![];
  for (i, l) in text.lines().enumerate() {
    // skip the first line (a {)
    if i == 0 {
      continue;
    }
    // skip the last line (})
    if l.starts_with("}") {
      continue;
    }
    let mut chars = l.chars();
    // drop the indentation
    for _ in 0..config.indent_width {
      chars.next();
    }
    buf.push(chars.as_str());
  }
  Some(buf.join("\n").to_string())
}

/// Formats the embedded HTML code blocks in JavaScript and TypeScript.
fn format_embedded_html(