Skip to content

[RFC] Introduce prettier-ignore#671

Merged
jlongster merged 1 commit intoprettier:masterfrom
vjeux:escape_hatch
Feb 14, 2017
Merged

[RFC] Introduce prettier-ignore#671
jlongster merged 1 commit intoprettier:masterfrom
vjeux:escape_hatch

Conversation

@vjeux
Copy link
Copy Markdown
Contributor

@vjeux vjeux commented Feb 12, 2017

This was surprisingly easy to write!

prettier-ignore will leave the expression the comment is attached to printed as it was before.

Fixes #120

@@ -0,0 +1,90 @@
exports[`test disable.js 1`] = `
"function a() {
// prettier-ignore-next-line
Copy link
Copy Markdown

@aaronyo aaronyo Feb 12, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the test producing a false positive somehow? It looks the the code is expecting "prettier-disable-next-line" rather than "...-ignore-..."

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I first named it ignore and then looked at eslint where it's disable. I must have forgotten to change this here :)

@aaronyo
Copy link
Copy Markdown

aaronyo commented Feb 12, 2017

My $.02 on naming: maybe // prettier-disable-next-node or even just // prettier-disable-next. If I'm understanding the code correctly, the scope of the escape hatch is the next AST node? I think it might actually confuse me a tad at first if it is "next-line" but it doesn't behave like eslint.

Regardless, I'll be happy to have this feature! Thank you!

@rtsao
Copy link
Copy Markdown
Contributor

rtsao commented Feb 12, 2017

Istanbul (which is fairly common) uses /* istanbul ignore next */ for skipping the next expression/block. Agreed that it seems confusing if next-line would actually ignore the next block/expression.

@vjeux
Copy link
Copy Markdown
Contributor Author

vjeux commented Feb 12, 2017

Thanks for the feedback, I think that prettier-ignore-next is the best choice.

@vjeux
Copy link
Copy Markdown
Contributor Author

vjeux commented Feb 13, 2017

Done!

@erbridge erbridge mentioned this pull request Feb 13, 2017
@jlongster
Copy link
Copy Markdown
Member

Yeah I was going to suggest a simpler name as well. We could even do // prettier-ignore and it would just read like a leading comment. I always have to look up eslint's ignore names because they are always 3-5 words. The easier we can make it to remember the better.

I don't think we need to worry about a learning curve and stick to eslint's conventions. This is something people will learn once and it's ok.

It there any chance you all would be ok with just // prettier-ignore?

@jlongster
Copy link
Copy Markdown
Member

I'm interested to see if this ever interacts badly with our formatting. There might be places where if you use this it will inject code that leaves it in a weird indentation state or something. But I think this is the right idea.

util.locStart(node),
util.locEnd(node)
);
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try adding some test cases where the expression is an argument to function, a property of an object, etc. Those interactions are where things might get weird.

The problem is the above code will naively output \n's and will mess up the measurement system. We might need split the content on newline and insert our own hardlines to make sure it never gets messed up. We might should add a breakParent just to make sure it always breaks up the expression too.

@vjeux
Copy link
Copy Markdown
Contributor Author

vjeux commented Feb 13, 2017

// prettier-ignore works for me. I can even remove the leading check so you can use it as a trailing comment if you want to.

@vjeux vjeux changed the title [RFC] Introduce prettier-disable-next-line [RFC] Introduce prettier-disable Feb 13, 2017
@vjeux vjeux changed the title [RFC] Introduce prettier-disable [RFC] Introduce prettier-ignore Feb 13, 2017
@aaronyo
Copy link
Copy Markdown

aaronyo commented Feb 13, 2017

+1 for // prettier-ignore

@jlongster
Copy link
Copy Markdown
Member

I can even remove the leading check so you can use it as a trailing comment if you want to.

Huh, that's an interesting idea. I suppose there's no reason why not to do that. Sure!

This was surprisingly easy to write!

Technically, it doesn't ignore the next line but the next expression or block but I'm guessing that people are already used to `// eslint-disable-next-line` so it's going to be an easier learning curve.

Fixes prettier#120
@vjeux
Copy link
Copy Markdown
Contributor Author

vjeux commented Feb 14, 2017

I just updated it to prettier-ignore and removed the leading check.

  // Incorrectly indented on purpose
      function f</* prettier-ignore */ T    :    B>(
        a : Array  <   number   > // prettier-ignore
      ) {

        call(
          f(         1          )
          // prettier-ignore
        )
      }

turns into

  // Incorrectly indented on purpose
  function f</* prettier-ignore */ T    :    B>(
    a : Array  <   number   > // prettier-ignore
  ) {
    call(
      f(         1          )
      // prettier-ignore
    );
  }

it works really well!

@jlongster
Copy link
Copy Markdown
Member

Haha... /me cringes. Well, unleash the hounds I suppose.

@jlongster jlongster merged commit 162ae7b into prettier:master Feb 14, 2017
@sonaye
Copy link
Copy Markdown

sonaye commented Mar 4, 2017

@vjeux how does this work exactly, can you summarize? couldn't find any docs on this. was checking on any #582 related updates.

@vjeux
Copy link
Copy Markdown
Contributor Author

vjeux commented Mar 4, 2017

Oops, forgot to add documentation.

If you put a comment named prettier-ignore, it is going to print the raw text of the node it is attached to.

@karlhorky
Copy link
Copy Markdown
Contributor

Would you guys want documentation for this? Where would it go? Just a quick paragraph with example in the readme?

@vjeux
Copy link
Copy Markdown
Contributor Author

vjeux commented Mar 22, 2017

@karlhorky yeah, would be awesome to have it in the README! PR welcome!

@karlhorky
Copy link
Copy Markdown
Contributor

karlhorky commented Mar 22, 2017

Alright, I'll take a look at this tomorrow!

@karlhorky
Copy link
Copy Markdown
Contributor

Ok, I've opened #1082.

vjeux pushed a commit that referenced this pull request Mar 23, 2017
@lock lock bot added the locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. label Jan 21, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Jan 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants