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

Martin Probst via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed May 10 12:44:07 PDT 2017


mprobst added a comment.

So, currently clang-format doesn't really understand trailing commas in parenthesized lists (such as parameter declarations or lists). It should, and coincidentally I was just yesterday trying to get that working in https://reviews.llvm.org/D33023.

Regarding the option – I'm not sure we need to introduce an option for this. I think I'd prefer to just always break before the `l_paren` if the parenthesized list has a trailing comma, similar to how we format array or object literals.

I'm not sure about indentation of this though,  there are multiple options that all seem reasonable-ish:

  // (1) wrap back to 0 indent
  fnCall(
      param,
      param,
      param,
  );
  
  function fnDecl(
      param,
      param,
      param,
  ) {
    code();
    here();    
  }
  
  // (2) wrap to +4 indent
  fnCall(
      param,
      param,
      param,
      );
  
  function fnDecl(
      param,
      param,
      param,
      ) {
    code();
    here();    
  }
  
  // (3) keep on line
  fnCall(
      param,
      param,
      param,);
  
  function fnDecl(
      param,
      param,
      param,) {
    code();
    here();    
  }

I was personally thinking more of option (2), as it's uncommon to me to wrap like (1) in the call situation. On the other hand (1) does look a lot better in the call situation, and also leaves more space for a return type. It's a stylistic question, so there isn't really a right or wrong, but I'd be cool with either of these, maybe with a preference for (1).

But in any case, if we can find agreement here, I think we should not introduce an option, and just make it how `clang-format` behaves for JS/TS code with trailing commas.


https://reviews.llvm.org/D33029





More information about the cfe-commits mailing list