Can clang-format put spaces inside JavaScript object literals’ braces?

Viewed 307

In JavaScript code like { foo: bar }, is there any way to make clang-format preserve the spaces just inside the braces?

I’ve studied the clang-format docs pretty carefully and the closest is SpacesInContainerLiterals, but that’ll only put spaces inside brackets, like [ 1, 2 ] (also my requirement) but removes spaces inside braces. (That config also adds spaces around colons inside braces, which I can’t have).

2 Answers

Ahmed Fasih is only partially correct. This option (Cpp11BracedListStyle: false) does not seem to work 100% of the time for import statements.

// input
import { Component, OnDestroy, OnInit, ViewEncapsulation } from '@angular/core';
// output
import {Component, OnDestroy, OnInit, ViewEncapsulation} from '@angular/core';

Looks like Cpp11BracedListStyle: false will work even on JavaScript files!

Related