Base solution for your next web application
Open Closed

Code formatting in Webstorm #12376


User avatar
0
ajayak created

Hi,

Please help me configure my code formatting in Webstorm.
For example:

import { NgModule } from '@angular/core';

The above is the formatting style in the base framework.
When I auto-format the code, it changes to

import {NgModule} from '@angular/core';

This makes the code style inconsistent and hard to manage and merge with future releases.


4 Answer(s)
  • User Avatar
    0
    oguzhanagir created
    Support Team

    Hi @ajayak

    It is recommended that you use the following code to format Angular codes. This way, no conflict will occur in other versions or the codes you formatted. At the same time, you apply the preconfigured prettier setting to the entire project.

    You can do this in a terminal in the Angular folder.

    "npx prettier --write ."
    
  • User Avatar
    0
    ajayak created

    Thanks @oguzhanagir.
    Do you know if I can configure this with Jetbrains webstorm IDE?

  • User Avatar
    0
    oguzhanagir created
    Support Team

    Hi @ajayak

    You can configure WebStorm to use the prettier settings available in the Angular project. You must follow the instructions in this document. Here you do not need to deal with parts such as the prettier file and the installation of the package. You can perform code formatting operations via WebStorm by specifying the prettier setting file under the Angular folder on the WebStorm side.

  • User Avatar
    0
    ajayak created

    Thankyou