[PATCH] D37142: clang-format: [JS] simplify template string wrapping.

Martin Probst via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 25 05:56:50 PDT 2017


mprobst created this revision.
Herald added a subscriber: klimek.

Previously, clang-format would try to wrap template string substitutions
by indenting relative to the openening `${`. This helped with
indenting structured strings, such as strings containing HTML, as the
substitutions would be aligned according to the structure of the string.

However it turns out that the overwhelming majority of template string +
substitution usages are for substitutions into non-structured strings,
e.g. URLs or just plain messages. For these situations, clang-format
would often produce very ugly indents, in particular for strings
containing no line breaks:

  return `<a href='http://google3/${file}?l=${row}'>${file}</a>(${
                                                                  row
                                                                },${
                                                                    col
                                                                  }): `;

This change makes clang-format indent template string substitutions as
if they were string concatenation operations. It wraps +4 on overlong
lines and keeps all operands on the same line:

  return `<a href='http://google3/${file}?l=${row}'>${file}</a>(${
      row},${col}): `;

While this breaks some lexical continuity between the `${` and `row}`
here, the overall effects are still a huge improvement, and users can
still manually break the string using `+` if desired.


https://reviews.llvm.org/D37142

Files:
  lib/Format/ContinuationIndenter.cpp
  unittests/Format/FormatTestJS.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D37142.112685.patch
Type: text/x-patch
Size: 4648 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170825/dad2e739/attachment.bin>


More information about the cfe-commits mailing list