Search code examples
javascripttypescriptvisual-studio-codeprettier

vscode : rearrange code for js / ts files


How can I rearrange the code in a .js / .ts file in Vscode? For example inside a Class, I want it to automatically put static variables at the top, then variables, then methods, etc.

I tried to google "vscode rearrange code" but it always point to Prettier, which does NOT do that.

Now maybe this feature doesn't exist on Javascript? But for example in Android Studio (Java) there definitely is an option to do that.

Also, I'm not talking about rearranging imports, I already know Vscode can do that.


Solution

  • As far as I know there is nothing built-in in VSCode or TypeScript that can do that. I'm not sure about any extensions though.

    However, if you use TSlint or ESlint, you can achieve the same thing with the member-ordering rule:

    The TSLint rule (though not the ESlint one) has a "fixer", so you can apply it with one click.