denoland / deno

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

`deno fmt`: ignore instructions doesn't seem to work on html files #26004

Open lowlighter opened 1 week ago

lowlighter commented 1 week ago

deno 2.0.0-rc.9 (release candidate, release, x86_64-unknown-linux-gnu) v8 12.9.202.13-rusty typescript 5.6.2

The docs suggest that you can bypass the fmt of html fileq but these instructions don't seem to work https://docs.deno.com/runtime/reference/cli/formatter/#markdown-%2F-html-%2F-css

Reproduction:

<!-- deno-fmt-ignore-file -->
<div>
      <p>
    foo
 </p>
</div>
<div>
  <!-- deno-fmt-ignore-start -->
      <p>
    foo
 </p>
  <!-- deno-fmt-ignore-end -->
</div>

Current behavior: image image

Note that running in non-check mode does indeed change the file, so it's not an issue with the --check flag.

I don't have an example but I think I've also tested the single line <!-- deno-fmt-ignore --> and it didn't work either.

Also not sure if there is a typo in the docs or not (there is one instruction with <!--- while others are <!-- which makes it a bit confusing): image

bartlomieju commented 6 days ago

@g-plane could you please take a look? From what I can gather, indeed only single line ignores should be possible with deno-fmt-ignore

g-plane commented 5 days ago

Ignoring a whole file is not supported at present, but I think this can be configured in deno.json by adding files to "exclude". Are there any reasons that you can't use config file?

lowlighter commented 5 days ago

I'm testing xml/html cases where the formatting/spacing is actually revelant (things like xml:space="preserve", or local white-space css property). A lot of libraries that optimize/transform xhtml usually honors the xml:space, but since deno fmt doesn't I figured out I'd test with the ignore instructions instead, but none of them seems to work (single-line, blocks and file). The only way is to use a <pre> in html, but it'd also nullify the test too because of its special signifiance

```html

foo

```
```diff -

foo

+

foo

```

I could register these files in the config as a work-around, but:

  1. It is unconsistent with the rest of the deno formatters that actually support ignore instructions
  2. The docs should not advertise a feature/behavior if it isn't actually working (should be either undocumented or actually implemented)
  3. My first intention was to disable partially the formatting for a specific section, not for the whole file (which I'd still like to be formatted)
  4. It's still a bit weird to be obliged to "pollute" your config file for a non-working feature

I don't mind if this is a temporary work-around, but I think in the long run 1 & 2 should definitely be addressed

g-plane commented 5 days ago

Unlike Markdown, it's impossible to use ignore-start and ignore-end for HTML, but you can use deno-fmt-ignore for a specific HTML element.

csvn commented 18 hours ago

I have the same issue but for CSS. That might be better as a separate issue, but I tried both of the below options:

/* deno-fmt-ignore-file */
html {
/** deno-fmt-ignore-file */
html {

The docs only mention HTML, but if HTML ignore directives aren't working CSS may have the same root cause.