denoland / deno

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

Failed on format html files with script tag containing block and template literal #25259

Open galiazzi opened 2 weeks ago

galiazzi commented 2 weeks ago

Version: Deno 1.46.1

An error occurs when trying to format an html file with script and a template string inside a block with break lines.

Example:

<!-- tt.html -->
<script>
{
  `First line
   second line`;
}
</script>
deno fmt --unstable-html tt.html

# Result
============================================================
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", "--unstable-html", "tt.html"]

thread 'tokio-runtime-worker' panicked at cli/tools/fmt.rs:763:11:
Formatting not stable. Bailed after 5 tries. This indicates a bug in the formatter where it formats the file (tt.html) differently each time. As a temporary workaround you can ignore this file.
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
yazan-abdalrahman commented 2 weeks ago

@lucacasonato @dsherret

It's Failed to assure format stability: "I tried to match if the current formatted text matches the following formatted file format, if the first four attempts do not match, will panic" So, I advise providing an external option flag in fmt to raise the number of format tries. Instead of panicking, we should provide the error message that tells them to delete certain break lines that can cure the problem and inform them how to increase the number of format stability tests? or it requires searches on upstream of the issue.

--unstable-html—what does it mean? it should not format if format not stable

dsherret commented 2 weeks ago

So, I advise providing an external option flag in fmt to raise the number of format tries.

I don't think we should do that. This is a bug that should be fixed and in the meantime the file the issue occurs on can be ignored.

galiazzi commented 2 weeks ago

An information, If the file is a vue the problem don't occurs:

<!-- tt.vue -->
<script>
{
  `First line
   second line`;
}
</script>
deno fmt --unstable-component tt.vue

# this works
Checked 1 file
g-plane commented 2 weeks ago

Tracked in: https://github.com/g-plane/markup_fmt/issues/50