prettier icon indicating copy to clipboard operation
prettier copied to clipboard

Prettier not respecting `prettier-ignore-start` and `prettier-ignore-end`

Open lamyergeier opened this issue 7 years ago • 17 comments

Prettier 1.15.2 Playground link

--parser markdown
--prose-wrap never

Input:

- **Sequence of initialization**:
<!-- prettier-ignore-start -->
  #. Firmware
  #. Bootloader (GNU Grub)
  #. Operating System Kernel
  #. Service Manager (e.g. `systemd`)
<!-- prettier-ignore-end -->

Output:

- **Sequence of initialization**:
  <!-- prettier-ignore-start -->
  #. Firmware #. Bootloader (GNU Grub) #. Operating System Kernel #. Service Manager (e.g. `systemd`)
  <!-- prettier-ignore-end -->

Expected behavior: See Input

lamyergeier avatar Nov 26 '18 21:11 lamyergeier

I can look into this

jaideng123 avatar Nov 29 '18 15:11 jaideng123

This is occurring because the only time we check for prettier-ignore start and end is on the children of the root node (which in this case would be [List]) and not in any of the deeper nodes. I'll start figuring out how to fix it

jaideng123 avatar Dec 02 '18 04:12 jaideng123

I checked the original PR for the code (#4202) and it looks like when it was merged in the intention was to only support top-level ignore-start/end so this isn't necessarily a bug but rather missing functionality @j-f1 Thoughts?

jaideng123 avatar Dec 02 '18 05:12 jaideng123

Seems like your evaluation is correct. If you’d like to add support for the comments in more places, feel free!

j-f1 avatar Dec 02 '18 11:12 j-f1

I'll take a crack at it

jaideng123 avatar Dec 04 '18 17:12 jaideng123

I'm not sure we want to support it in more places. Ignore comment is intended to be a escape hatch, not a feature we want to extend

duailibe avatar Dec 04 '18 18:12 duailibe

@anishmittal2020 It's already possible to ignore them, is this what you want?

Prettier 1.15.3 Playground link

--parser markdown
--prose-wrap never

Input:

- **Sequence of initialization**:

  <!-- prettier-ignore -->
  #. Firmware
  #. Bootloader (GNU Grub)
  #. Operating System Kernel
  #. Service Manager (e.g. `systemd`)
  
  __formatting still works here__

Output:

- **Sequence of initialization**:

  <!-- prettier-ignore -->
  #. Firmware
  #. Bootloader (GNU Grub)
  #. Operating System Kernel
  #. Service Manager (e.g. `systemd`)

  **formatting still works here**

ikatyang avatar Dec 05 '18 04:12 ikatyang

@ikatyang

  • this works but do we need to give 2 blank spaces before <!-- prettier-ignore --> for it to work?
  • Also, IMHO <!-- prettier-ignore-start --> and <!-- prettier-ignore-end --> is a better option as it is very explicitly clear what part should be ignored. If we use <!-- prettier-ignore --> then we need to use it every time we have a blank line in a range.

Summary:

  • IMHO Range ignore seems to be more semantically clear and the file looks cleaner. Is more elegant.
  • If a user uses range ignore, he can be mentally sure that the range should be ignored no matter how the content in the range is formatted (i.e. with or without blank lines).

Prettier 1.15.3 Playground link

--parser markdown
--prose-wrap never

Input:

  <!-- prettier-ignore -->
  a) regular use
    1. finish something worthy of a commit
    2. commit
  b) independent fixup
    1. realize that something does not work
    2. fix that
    3. commit it

Output:

  <!-- prettier-ignore -->

a) regular use 1. finish something worthy of a commit 2. commit b) independent fixup 1. realize that something does not work 2. fix that 3. commit it

Expected behavior: See Input


NOTE: The following Input itself has not been rendered correctly here, please go to the playground link

Prettier 1.15.3 Playground link

--parser markdown
--prose-wrap never

Input:

- Workflow
  <!-- prettier-ignore -->
  a) regular use
  <!-- prettier-ignore -->
	1. finish something worthy of a commit
    2. commit
  <!-- prettier-ignore -->
  b) independent fixup
  <!-- prettier-ignore -->
    1. realize that something does not work
    2. fix that
    3. commit it

Output:

- Workflow
  <!-- prettier-ignore -->
  a) regular use
  <!-- prettier-ignore -->
  
	1. finish something worthy of a commit
  2. commit
     <!-- prettier-ignore -->
     b) independent fixup
     <!-- prettier-ignore -->
  1. realize that something does not work
  1. fix that
  1. commit it

Expected behavior: See Input

lamyergeier avatar Dec 05 '18 08:12 lamyergeier

It seems you'd like to use pandoc-specific syntax in some places but the rest of them are still valid CommonMark. I think it'd be better to find a remark plugin to support pandoc instead of using a lot of range ignore but I'm not sure if there's one.

ikatyang avatar Dec 05 '18 09:12 ikatyang

Yes, if we could do prettier ignore for a range at any place in the document, it will be great. I think many people would like that, as I think many people might use other standard (like pandoc) for certain things rarely, but mostly they follow commonmark.

I understand from @duailibe comment that Prettier want's to enforce standard and weed out nonstandard things. IMHO: In the case of source code, people use prettier to standardize code that can be shared. But in the case of markdown usually, people share the generated HTML or PDF and not markdown. So, I think that this feature can be extended to markdown and limited only to Markdown and not to other language like Javascript etc. If people could use some non-standard markdown, it should be ok as they don't share the source or the markdown file itself.

Also, sensible people won't misuse prettier-ignore as they would use it rarely because using this at all the places is as good as not using prettier at all.

lamyergeier avatar Dec 05 '18 14:12 lamyergeier

Life has gotten a little busy for me recently so I'm going to step off this issue and open it up for anyone else that wants to work on it

jaideng123 avatar Dec 10 '18 21:12 jaideng123

I think @anishmittal2020 is onto a great suggestion here. Allowing an explicit range ignore anywhere in any prettier supported file would be very helpful. This kind of implementation is present in many other platform linters and formatters. If you try this out in a prettier playground the range ignore is being ignored 🙈

<!-- prettier-ignore-start -->
<div  class="dark-background">
  </div>
<div class='light-background'></div>
<a href=""/>
<!-- prettier-ignore-end -->

As mentioned above inserting <-- prettier-ignore --> multiple times is not a very nice implementation. A common example would be partials in a HTML file where I would need to do the following...

<!-- prettier-ignore -->
{{ define "title" }}
<!-- prettier-ignore -->
{{ .Title }} &ndash; {{ .Site.Title }}
<!-- prettier-ignore -->
{{ end }}
<!-- prettier-ignore -->
{{ define "main" }}
<!-- prettier-ignore -->
{{ .Content }}
<!-- prettier-ignore -->
{{ end }}

<!-- The rest of my HTML I would like to be formatted -->

Would be much cleaner to be able to do the this...

<!-- prettier-ignore-start -->
{{ define "title" }}
{{ .Title }} &ndash; {{ .Site.Title }}
{{ end }}
{{ define "main" }}
{{ .Content }}
{{ end }}
<!-- prettier-ignore-end -->

<!-- The rest of my HTML I would like to be formatted -->

Is this being worked on by anyone?

jimmyhoran avatar Jan 28 '19 01:01 jimmyhoran

@jimmyhoran

If you try this out in a prettier playground the range ignore is being ignored :see_no_evil:

<!-- prettier-ignore-start -->
<div  class="dark-background">
  </div>
<div class='light-background'></div>
<a href=""/>
<!-- prettier-ignore-end -->

It should actually work if you add a blank line before the end tag:

<!-- prettier-ignore-start -->
<div  class="dark-background">
  </div>
<div class='light-background'></div>
<a href=""/>

<!-- prettier-ignore-end -->

At least that's the behavior I get in this Prettier playground.

pawamoy avatar Sep 27 '20 15:09 pawamoy

See also the explanation in https://github.com/prettier/prettier/issues/7027#issuecomment-557825254

thorn0 avatar Sep 28 '20 08:09 thorn0

Check https://prettier.io/docs/en/ignore.html

reduardo7 avatar Feb 18 '21 14:02 reduardo7

@jimmyhoran The request to support ranges in any language is here: #5287

mrwensveen avatar Aug 04 '24 13:08 mrwensveen

It should actually work if you add a blank line before the end tag:

Lifesaver. Thanks a bunch @pawamoy

yermulnik avatar Aug 16 '24 13:08 yermulnik