denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
93.96k stars 5.23k forks source link

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

Closed gabeidx closed 3 days ago

gabeidx commented 3 weeks ago

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 but smart enough to not apply them to YAML files and not panic.

g-plane commented 3 weeks ago

Thanks for feedback! I'm investigating this.

g-plane commented 2 weeks ago

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.

gabeidx commented 2 weeks ago

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.