[RFC] Introduce prettier-ignore#671
Conversation
| @@ -0,0 +1,90 @@ | |||
| exports[`test disable.js 1`] = ` | |||
| "function a() { | |||
| // prettier-ignore-next-line | |||
There was a problem hiding this comment.
Is the test producing a false positive somehow? It looks the the code is expecting "prettier-disable-next-line" rather than "...-ignore-..."
There was a problem hiding this comment.
I first named it ignore and then looked at eslint where it's disable. I must have forgotten to change this here :)
|
My $.02 on naming: maybe Regardless, I'll be happy to have this feature! Thank you! |
|
Istanbul (which is fairly common) uses |
|
Thanks for the feedback, I think that prettier-ignore-next is the best choice. |
|
Done! |
|
Yeah I was going to suggest a simpler name as well. We could even do 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 |
|
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) | ||
| ); | ||
| } |
There was a problem hiding this comment.
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.
|
|
|
+1 for |
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
|
I just updated it to // 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! |
|
Haha... /me cringes. Well, unleash the hounds I suppose. |
|
Oops, forgot to add documentation. If you put a comment named |
|
Would you guys want documentation for this? Where would it go? Just a quick paragraph with example in the readme? |
|
@karlhorky yeah, would be awesome to have it in the README! PR welcome! |
|
Alright, I'll take a look at this tomorrow! |
|
Ok, I've opened #1082. |
This was surprisingly easy to write!
prettier-ignorewill leave the expression the comment is attached to printed as it was before.Fixes #120