Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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).

like image 603
Ahmed Fasih Avatar asked Nov 07 '22 22:11

Ahmed Fasih


1 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';
like image 59
Taylor Buckner Avatar answered Nov 10 '22 00:11

Taylor Buckner