]> granicus.if.org Git - clang/commit
clang-format: [JS] simplify template string wrapping.
authorMartin Probst <martin@probst.io>
Tue, 29 Aug 2017 08:30:07 +0000 (08:30 +0000)
committerMartin Probst <martin@probst.io>
Tue, 29 Aug 2017 08:30:07 +0000 (08:30 +0000)
commit2958bc209c92eefb9b216afa3917cf9307c9fb19
tree10e9d1e284b6cdc91b7a5e1284c4716e1d9de1dc
parent918910d6e53db4b620ae1167dc59e83f3031750e
clang-format: [JS] simplify template string wrapping.

Summary:
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.

Reviewers: djasper

Subscribers: klimek, cfe-commits

Differential Revision: https://reviews.llvm.org/D37142

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@311988 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Format/ContinuationIndenter.cpp
unittests/Format/FormatTestJS.cpp