public function format()

in src/HackfmtFormatter.hack [20:50]


  public function format(
    string $code,
    string $_file_name,
  ): string {
    $output = varray[];
    $exit_code = null;

    $tempnam = \tempnam(
      \sys_get_temp_dir(),
      'hack-codegen-hackfmt',
    );

    $options = $this->getFormattedOptions();

    try {
      \file_put_contents($tempnam, $code);
      \exec(
        'hackfmt '.$options.' '.\escapeshellarg($tempnam),
        inout $output,
        inout $exit_code,
      );
    } finally {
      \unlink($tempnam);
    }

    invariant(
      $exit_code === 0,
      'Failed to invoke hackfmt',
    );
    return Str\join($output, "\n")."\n";
  }