typescriptphpstormwebstormtslintcode-standards

How to sort imports alphabetically for TypeScript files automatically in WebStorm / PhpStorm?


I use tslint with default config tslint:recommended and I want to adapt as less rules as possible.

Certain rules enforce that imports should be alphabetized:

src/core/task/TaskMockDecorator.ts[2, 1]: Import sources within a group must be alphabetized.
src/core/task/taskRunner.ts[1, 16]: Named imports must be alphabetized.

I don't want to sort the imports alphabetically by myself. Before I disable that linting: Can WebStorm / PhpStorm do that for me?


Solution

  • According to webstorm: https://www.jetbrains.com/help/webstorm/tslint.html

    With WebStorm, you can fix some of the issues reported by TSLint > automatically.

    To fix a specific error, place the cursor at the highlighted code, press ⌥⏎, and then choose TSLint: fix current error from the pop-up menu. To fix all the issues detected in the file, choose TSLint: fix current file.