deno icon indicating copy to clipboard operation
deno copied to clipboard

Bug: `deno fmt` panics with `--unstable-yaml` and `--use-tabs`

Open gabeins opened this issue 1 year ago • 1 comments

Version: Deno 1.46.1 (stable, release, aarch64-apple-darwin)

Given an example yaml file, when deno fmt --use-tabs --unstable-yaml example.yml is run, a panic occurs with an "invalid indentation" error.

# example.yml
steps:
  - name: Clone repository
    uses: actions/checkout@v4
deno fmt --use-tabs --unstable-yaml example.yml

============================================================
Deno has panicked. This is a bug in Deno. Please report this
at https://github.com/denoland/deno/issues/new.
If you can reliably reproduce this panic, include the
reproduction steps and re-run with the RUST_BACKTRACE=1 env
var set and include the backtrace in your report.

Platform: macos aarch64
Version: 1.46.1
Args: ["deno", "fmt", "--use-tabs", "--unstable-yaml", "example.yml"]

thread 'tokio-runtime-worker' panicked at cli/tools/fmt.rs:749:13:
Formatting succeeded initially, but failed when ensuring a stable format. This indicates a bug in the formatter where the text it produces is not syntactically correct. As a temporary workaround you can ignore this file (/Users/gabe/Projects/tmp/deno-bug-fmt-yaml/example.yml).

parse error at line 3, column 3
  |
3 | 		uses: actions/checkout@v4
  |   ^
invalid indentation
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

After some digging, I've found that the pretty_yaml crate does accept a useTabs config property, so it technically can work with Deno's --use-tabs flag.

Expected Outcome

The formatter should be aware of the project's preferred indentation settings and pass them down to the underlying formatting tool.

gabeins avatar Aug 23 '24 07:08 gabeins

Thanks for feedback! I'm investigating this.

g-plane avatar Aug 23 '24 09:08 g-plane

I'm going to remove useTabs option from pretty_yaml, since YAML doesn't allow tabs as indentations, as the spec says:

To maintain portability, tab characters must not be used in indentation, since different systems treat tabs differently.

g-plane avatar Aug 23 '24 23:08 g-plane

I'm going to remove useTabs option from pretty_yaml,

That makes sense 💯.

The expectation from a Deno user PoV would be to have the YAML formatted to spec even if the project's fmt configuration uses tabs.

gabeins avatar Aug 24 '24 07:08 gabeins