vscode : rearrange code for js / ts files [closed]

懵懂的女人 提交于 2019-12-13 02:49:23

问题


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.


回答1:


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:

  • https://palantir.github.io/tslint/rules/member-ordering/
  • https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/member-ordering.md

These linters have "fixers", so you can apply the rule with one click.



来源:https://stackoverflow.com/questions/58894055/vscode-rearrange-code-for-js-ts-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!