Search code examples
javascripttypescriptcode-formatting

Does a code transformer / formatter exist that will add curly braces to Typescript code


I want all the code in our repository to always use blocks enclosed with brackets for the clauses of if statements, loops and even for inline functions. The following code is banned:

const func = () => doSomething();

It should be converted to:

const func = () => {
  return doSomething();
};

It's personal preference, of course, but I think if only the latter is checked in, then diffs are easier to read, it's easier to add and remove debug logging, and you are less likely to accidentally check in changes that have no impact on the logic.

Prettier won't do this, it is considered beyond its scope. But there must be some tools that do it. I've done google searches but found nothing.


Solution

  • ESLint has the arrow-body-style always option, which supports autofixing.