Home > OS >  Avoid VSCode refactor format for svelte render conditionals
Avoid VSCode refactor format for svelte render conditionals

Time:09-29

I have the following code:

{#if variable_A > 750}
        CODE HERE
{:else}
    {#if variable_B == false}
        CODE HERE
    {:else}
        MORE CODE HERE
    {/if}
{/if}

When pressing save, the code is automatically refactored and formatted by the Svelte for VS Code extension to:

{#if variable_A > 750}
        CODE HERE
{:else if variable_B == false}
        CODE HERE
{:else}
        MORE CODE HERE
{/if}

The result is technically correct, but I still prefer the first version. Is there a way to disable this type of refactor, without disabling the auto format entirely?

CodePudding user response:

{#if variable_A > 750}
            CODE HERE
 {:else}
        {#if variable_B == false}
            CODE HERE
        {:else}
            MORE CODE HERE
        {/if}
 {/if}

It formats to

    {#if variable_A > 750}
            CODE HERE
    {:else if variable_B == false}
            CODE HERE
    {:else}
            MORE CODE HERE
    {/if}

But add some code above the if then it does not

    {#if variable_A > 750}
            CODE HERE
    {:else}
        Some code here also then it will not format like above and stay as it is
        {#if variable_B == false}
            CODE HERE
        {:else}
            MORE CODE HERE
        {/if}
    {/if}

This way you can keep the code which does not combine the if else

  • Related