CLion 2018.3 Help

Prettier

Prettier is a tool to format .js, .ts, .css, .less, .scss, .vue, and .json code. With CLion, you can format selected code fragments as well as entire files or directories using the Reformat with Prettier action. CLion adds this action as soon as you install Prettier as a dependency in your project or globally on your computer.

Before you start

  1. Download and install Node.js.

  2. Install and enable the Prettier repository plugin on the Plugins page as described in Plugins.

To install Prettier

  1. Open the embedded Terminal (Alt+F12).

  2. At the command prompt, type npm install --save-dev --save-exact prettier or npm install --global prettier. Learn more about installation modes from the Prettier official website.

To configure Prettier in CLion

  1. In the Settings/Preferences dialog (Ctrl+Alt+S), click JavaScript under Languages and Frameworks, and then click Prettier.

  2. On the Prettier page, that opens, specify the path to the prettier package and choose the Node.js interpreter to use. If you choose the Project alias, CLion will automatically use the project default interpreter from the Node interpreter field on the Node.js and NPM page.

    In most cases, CLion detects the project default interpreter and fills in the field itself. You can also choose another configured local interpreter or click browseButton and configure a new one.

To reformat code with Prettier

  • Select the code fragment to reformat in the editor or select a file or a folder in the Project tool window and press N/A or choose Reformat with Prettier on the context menu of the selection.

  • Alternatively, press Ctrl+Shift+A and click Reformat with Prettier in the Find Action list.

    ws_reformat_with_prettier_js.png

CLion can apply the key code style rules from the Prettier's configuration to the CLion Code Style settings so that generated code (e.g. after refactoring or quick-fix) and the code that is already processed with Prettier are formatted consistently.

To apply Prettier code style rules

  • In the project where Prettier is enabled, open package.json and click Yes in the pane at the top of the tab.

    Pane above package.json: apply Prettier code style

Last modified: 15 January 2019