[PATCH] D73354: clang-format: insert trailing commas into containers.

Martin Probst via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 24 07:26:23 PST 2020


mprobst created this revision.
mprobst added reviewers: krasimir, MyDeveloperDay.
Herald added a project: clang.

This change adds an option to insert trailing commas into container
literals. For example, in JavaScript:

  const x = [
    a,
    b,
     ^~~~~ inserted if missing.
  ]

This is implemented as a seperate post-processing pass after formatting
(because formatting might change whether the container literal does or
does not wrap). This keeps the code relatively simple and orthogonal,
though it has the notable drawback that the newly inserted comma is not
taken into account for formatting decisions (e.g. it might exceed the 80
char limit).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D73354

Files:
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  clang/unittests/Format/FormatTestJS.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D73354.240191.patch
Type: text/x-patch
Size: 17894 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200124/d85e31ed/attachment-0001.bin>


More information about the cfe-commits mailing list