Rearranging Code Using Arrangement Rules
WebStorm provides the Code rearrangement functionality that helps you make your code more readable and consistent. With it, you can configure how different blocks of code, such as the constructor, the fields, and the methods are ordered in a JavaScript or TypeScript class. In addition, you can configure whether the fields and methods should be ordered by name.
On this page:
Defining rearrangement rules
- Open the Settings / Preferences Dialog by pressing Ctrl+Alt+S or by choosing for Windows and Linux or for macOS, and click Code Style under Editor.
- Under the Code Style node, choose JavaScript or TypeScript.
- On the Code Style. JavaScript or Code Style. TypeScript page, define the rules for rearranging your code. tab of the
Rearranging code
You can invoke code rearrangement via the Find Action popup or as a part of code reformatting.
To invoke rearrangement via Find Action
Choose or press Ctrl+Shift+A, start typing Rearrange Code
, and then choose Rearrange Code
from the list.
To run rearrangement during code reformatting
Open the Reformat Code dialog box by pressing Ctrl+Shift+Alt+L and select the Rearrange Code check box. Your code will be rearranged every time the Reformat code action is invoked.