[PATCH] D33029: [clang-format] add option for dangling parenthesis

Ryan Stringham via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed May 10 13:04:21 PDT 2017


stringham added a comment.

I think we should have the option whether or not a trailing comma is preset for a few reasons:

1. clang-format doesn't support enforcing adding trailing commas
2. trailing commas aren't always supported (if you use the rest operator)
  - `Uncaught SyntaxError: Rest parameter must be last formal parameter`
3. if you break before the opening paren, treating the surrounding parens as a "block" helps the developer match up the parens.

false:

  longFunctionCall(new longClassNameBeingInitialized(
      param1,
      param2,
      param3,
      param4,
      param5));

true:

  longFunctionCall(new longClassNameBeingInitialized(
      param1,
      param2,
      param3,
      param4,
      param5
  ));

also happens for function calls like this:

false:

  this.myList = [
      param1,
      functionCall(param)
          .chainedCall(
              longparam1,
              function(foo) {
                  return calculateSomething(foo);
              }),
      param3,
  ];

true:

  this.myList = [
      param1,
      functionCall(param)
          .chainedCall(
              longparam1,
              function(foo) {
                  return calculateSomething(foo);
              }
          ),
      param3,
  ];

can't put a trailing comma with the rest operator
false:

  class MyClass {
      constructor(
          param1,
          param2,
          ...args) {
          this.p1 = param1;
      }
  }

true:

  class MyClass {
      constructor(
          param1,
          param2,
          ...args
      ) {
          this.p1 = param1;
      }
  }


https://reviews.llvm.org/D33029





More information about the cfe-commits mailing list