-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Disable formatting a region of code using directives #18261
Comments
Hi there, |
Hi, oh it would be great to have the ability to prevent specific pieces of code from being formatted. Louie |
I would want to use this for multiline strings, which need very careful whitespace inclusions. |
What about doing a similar stuff than PhpStorm ? :
|
There are formatters in the marketplace that support this, but I don't like many of them for various other issues. How's the support for the native formatter going? I wonder, what is the "More Feedback" that is expected? Can we have the flag removed? |
// prettier-ignore |
No news about this?. Is a nice feature that sometimes is required because the formatter is not the best in some situations, but looks like the idea is abandoned. |
Some more feedback here. Possible directive structure for the feature:Disables formatting until the closure end. If placed within the file's top level, then until the end of the file. If placed at the beginning of the file, that implies disabling formatter for the whole file.
Clears any formatting disables active until this point.
Just for the next line. Additional lines of multi-line statements will be formatted.
Just for the current line (left from the comment). Additional lines of multi-line statements will be formatted.
For the whole statement, includes multiple lines.
Disables until closure end
Closing notes: Not sure how tied this is to TypeScript itself and the |
The problem I see here that the whole idea seems not to be interesting enough to be considering / work on. |
Would very much like to have this feature available as well. |
This comment was marked as spam.
This comment was marked as spam.
Just endorsing the desirability of this feature.
|
I very need this too, for same reasons. I have a complex set of arrays, with specific structure. I need to keep it nicely formatted as a table, just to understand what is going on there. |
Adding my vote. Personally, I find it useful to be able to line things up in code for these reasons:
I don't do it often (and it can definitely be overdone), but it's saved me and my team from mistakes in the past. I like the way that the Black formatter for Python handles it: # fmt: off
create_test_user(name="Admin User", role="admin", theme="dark")
create_test_user(name="Normal User", role="registered", theme="light")
create_test_user(name="Guest User", role=None, theme=None)
# fmt: on |
Hi! It would be awesome to have this feature! Thanks for your amazing work! |
Hi all, I implemented format ignore directivies in vscode plugin (patches native ts formatter), it currently works like so: const a = {
//@ts-format-ignore-region
a: 1,
a1: 2,
//@ts-format-ignore-endregion
b: 3,
//@ts-format-ignore-line
c: 4,
} Only And I wonder whether 3 directives suggested by @ackvf are enough? |
Great news, finally! I've already tried it and it works perfectly. Thank you. However I have one request - could it work also with space before the comment line? Like Also - is it possible to make it as standalone extension? There are plenty of features and it is more complicated to recommend this the all-in-one type of extension to the team. Thanks! |
This comment was marked as off-topic.
This comment was marked as off-topic.
Wow, I say that's customer service I like :) Thank you, tested and works perfectly. Regarding this issue, as for me, I consider this a "greater half" of the work done. I very much like that the command comments are consistent with original comments, this IMHO should be implemented there in the native formatter in the first place, but whatever... Now we have it anyway, finally! The standalone extension will be definitely very welcome, but in the meantime I use the whole bundle and I see no problems so far, so good job and again, thank you. |
Agree & thanks!
From: tomhanax ***@***.***>
Reply-To: microsoft/TypeScript ***@***.***>
Date: Sunday, February 5, 2023 at 10:25 PM
To: microsoft/TypeScript ***@***.***>
Cc: Josh Kramer ***@***.***>, Comment ***@***.***>
Subject: Re: [microsoft/TypeScript] Disable formatting a region of code using directives (#18261)
Sorry hotfix was there, but forgot to release it instantly.. Now its definitely here!
Wow, I say that's customer service I like :) Thank you, tested and works perfectly. Regarding this issue, as for me, I consider this a "greater half" of the work done. I very much like that the command comments are consistent with original comments, this IMHO should be implemented there in the native formatter in the first place, but whatever... Now we have it anyway, finally!
The standalone extension will be definitely very welcome, but in the meantime I use the whole bundle and I see no problems so far, so good job and again, thank you.
—
Reply to this email directly, view it on GitHub<#18261 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/ACCIEBPZIL7HKE3XPTZ353TWWCKM7ANCNFSM4DZWFP4A>.
You are receiving this because you commented.Message ID: ***@***.***>
|
@zardoy thank you, that's amazing. I have one question, it only works if I disable Typescript plugin. Is that the right way? Or I have to configure it somehow to work with Typescript plugin enabled? |
What TypeScript plugin are you talking about?? If you disable aforementioned extension it obviously won't work. Or do you mean something else? |
I mean this one https://marketplace.visualstudio.com/items?itemName=ms-vscode.vscode-typescript-next |
@alexbezhan Good question! You see, there is following in TS 5.0 changelog:
And it even currently breaks plugin in so many places 🤣 But I changed format features implementation, so should be good now here. |
with clangFormat for C/C++ you can use
|
+1 |
From: microsoft/vscode#33772
TypeScript Version: 2.4.0 / nightly (2.5.0-dev.201xxxxx)
Feature Request
Add a way to disable formatting of a region of code. An example of this is js beatuify's preserve directive:
The text was updated successfully, but these errors were encountered: