Typescript: Disable formatting a region of code using directives

Created on 5 Sep 2017  ·  5Comments  ·  Source: microsoft/TypeScript



From: https://github.com/Microsoft/vscode/issues/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:

// Use preserve when the content is not javascript, but you don't want it reformatted.
/* beautify preserve:start */
{
    browserName: 'internet explorer',
    platform:    'Windows 7',
    version:     '8'
}
/* beautify preserve:end */
Awaiting More Feedback Formatter Suggestion VS Code Tracked

Most helpful comment

Hi,

oh it would be great to have the ability to prevent specific pieces of code from being formatted.

Louie

All 5 comments

Hi there,
It will be great to have ability to prevent specific pieces of code from being formatted.
In my case JS code can contains 3-rd party snippets that are minified pieces of JS (Google analytics, conversion scripts etc.). I'd prefer to not format them on paste/update by specifying directives or something.

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 ? :

<div>
<!-- @formatter:off -->
<div
    class="unformated-div"
><div>
<!-- @formatter:on -->
</div>

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?

Was this page helpful?
0 / 5 - 0 ratings