fn format_ensure_stable(
  file_path: &Path,
  file_text: &str,
  fmt_options: &FmtOptionsConfig,
  fmt_func: impl Fn(
    &Path,
    &str,
    &FmtOptionsConfig,
  ) -> Result<Option<String>, AnyError>,
) -> Result<Option<String>, AnyError> {
  let formatted_text = fmt_func(file_path, file_text, fmt_options)?;

  match formatted_text {
    Some(mut current_text) => {
      let mut count = 0;
      loop {
        match fmt_func(file_path, &current_text, fmt_options) {
          Ok(Some(next_pass_text)) => {
            // just in case
            if next_pass_text == current_text {
              return Ok(Some(next_pass_text));
            }
            current_text = next_pass_text;
          }
          Ok(None) => {
            return Ok(Some(current_text));
          }
          Err(err) => {
            panic!(
              concat!(
                "Formatting succeeded initially, but failed when ensuring a ",
                "stable format. This indicates a bug in the formatter where ",
                "the text it produces is not syntatically correct. As a temporary ",
                "workfaround you can ignore this file.\n\n{:#}"
              ),
              err,
            )
          }
        }
        count += 1;
        if count == 5 {
          panic!(
            concat!(
              "Formatting not stable. Bailed after {} tries. This indicates a bug ",
              "in the formatter where it formats the file differently each time. As a ",
              "temporary workaround you can ignore this file."
            ),
            count
          )
        }
      }
    }
    None => Ok(None),
  }
}
/// When storing any formatted text in the incremental cache, we want
/// to ensure that anything stored when formatted will have itself as
/// the output as well. This is to prevent "double format" issues where
/// a user formats their code locally and it fails on the CI afterwards.
When storing any formatted text in the incremental cache, we want
to ensure that anything stored when formatted will have itself as
the output as well. This is to prevent "double format" issues where
a user formats their code locally and it fails on the CI afterwards.
When storing any formatted text in the incremental cache we want to ensure that anything stored when formatted will have itself as the output as well . This is to prevent " double format " issues where a user formats their code locally and it fails on the CI afterwards .
fn format_ensure_stable(
  file_path: &Path,
  file_text: &str,
  fmt_options: &FmtOptionsConfig,
  fmt_func: impl Fn(
    &Path,
    &str,
    &FmtOptionsConfig,
  ) -> Result<Option<String>, AnyError>,
) -> Result<Option<String>, AnyError> {
  let formatted_text = fmt_func(file_path, file_text, fmt_options)?;
  match formatted_text {
    Some(mut current_text) => {
      let mut count = 0;
      loop {
        match fmt_func(file_path, &current_text, fmt_options) {
          Ok(Some(next_pass_text)) => {
            // just in case
            if next_pass_text == current_text {
              return Ok(Some(next_pass_text));
            }
            current_text = next_pass_text;
          }
          Ok(None) => {
            return Ok(Some(current_text));
          }
          Err(err) => {
            panic!(
              concat!(
                "Formatting succeeded initially, but failed when ensuring a ",
                "stable format. This indicates a bug in the formatter where ",
                "the text it produces is not syntatically correct. As a temporary ",
                "workfaround you can ignore this file.\n\n{:#}"
              ),
              err,
            )
          }
        }
        count += 1;
        if count == 5 {
          panic!(
            concat!(
              "Formatting not stable. Bailed after {} tries. This indicates a bug ",
              "in the formatter where it formats the file differently each time. As a ",
              "temporary workaround you can ignore this file."
            ),
            count
          )
        }
      }
    }
    None => Ok(None),
  }
}
fn format_ensure_stable ( file_path : & Path , file_text : & str , fmt_options : & FmtOptionsConfig , fmt_func : impl Fn ( & Path , & str , & FmtOptionsConfig , ) -> Result < Option < String > , AnyError > , ) -> Result < Option < String > , AnyError > { let formatted_text = fmt_func ( file_path , file_text , fmt_options ) ? ; match formatted_text { Some ( mut current_text ) => { let mut count = 0 ; loop { match fmt_func ( file_path , & current_text , fmt_options ) { Ok ( Some ( next_pass_text ) ) => { // just in case if next_pass_text == current_text { return Ok ( Some ( next_pass_text ) ) ; } current_text = next_pass_text ; } Ok ( None ) => { return Ok ( Some ( current_text ) ) ; } Err ( err ) => { panic ! ( concat ( " " " " " " " \n \n " ) err ) } } count += 1 ; if count == 5 { panic ! ( concat ( " " " " " " ) count ) } } } None => Ok ( None ) , } }
When storing any formatted text in the incremental cache, we want
to ensure that anything stored when formatted will have itself as
the output as well.
When storing any formatted text in the incremental cache we want to ensure that anything stored when formatted will have itself as the output as well .
file_path
&Path
file_text
&str
fmt_options
&FmtOptionsConfig
fmt_func
impl Fn(
    &Path,
    &str,
    &FmtOptionsConfig,
  ) -> Result<Option<String>, AnyError>
file_path
&Path
file_text
&str
fmt_options
&FmtOptionsConfig
fmt_func
impl Fn(
    &Path,
    &str,
    &FmtOptionsConfig,
  ) -> Result<Option<String>, AnyError>