Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to format curly braces for autoformat in intellij

Whenever I hit alt-cmd-l to autoformat my code, it formats my imports and arrays from:

import { CommonModule } from '@angular/common';
let arr = [ myStringVar ]; // simple example, just go with it

to

import {CommonModule} from '@angular/common';
let arr = [myStringVar];

How do I tell IntelliJ to put a space after the opening brace and before the close brace when auto-formatting? (Specifically for javascript, typescript)

I've looked around for the answer and could not find one or asked the question badly. So I apologize if this is duplicate.

I'm on Intellij 2016.3.3

like image 912
Machtyn Avatar asked Jan 27 '17 21:01

Machtyn


People also ask

How do I autoformat in IntelliJ?

Automatically reformat code on savePress Ctrl+Alt+S to open the IDE settings and select Tools | Actions on Save. Enable the Reformat code option.

How do I change the bracket in IntelliJ?

From the IntelliJ documentation: Go to the menu File | Settings | Project Settings | Code Style - Java. Select the 'Wrapping and braces' tab. Set 'Braces placement options' to 'Next line'.

How do I auto correct indentation in IntelliJ?

Automatically detect indentsPress Ctrl+Alt+S to open the IDE settings and select Editor | Code Style. Select the Detect and use existing file indents for editing checkbox. Apply the changes and close the dialog.

How do I fix format in IntelliJ?

Sometimes code formatting can get out of sync, but there's an easy fix in IntelliJ IDEA. You can use ⌘⌥L (macOS), or Ctrl+Alt+L (Windows/Linux) to reformat a selection of code according to your reformat settings.


1 Answers

Go to preference, select Editor > Code Style > Javascript and choose Spaces, check the checkboxes in Within section "ES6 import/export brances", and if you want spaces in object literal braces, check "Object literal braces" and as well.

like image 92
Liutong Chen Avatar answered Oct 05 '22 14:10

Liutong Chen