[PATCH] D133589: [clang-format] JSON formatting add new option for controlling newlines in json arrays
MyDeveloperDay via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sat Sep 10 06:03:23 PDT 2022
MyDeveloperDay added a comment.
Addressed review comments, renamed the options
================
Comment at: clang/docs/ClangFormatStyleOptions.rst:3115
+**JsonMultilineArrays** (``Boolean``) :versionbadge:`clang-format 16`
+ If ``true``, clang-format will always break after a Json array `[`
----------------
curdeius wrote:
> Why limiting to JSON only?
> Could we name it in a general fashion (we comment that it's JSON only for the time being). I believe it may be an interesting option for various languages.
>
> How about BreakMultilineArrays, or just BreakArrays to follow the naming of existing options a bit?
I'm going to change the name to be `BreakArrays` but I'm not 100% sure who it might help other languages, but maybe we can look at this afterwards so having a good name now will help us later on.
================
Comment at: clang/lib/Format/TokenAnnotator.cpp:4405-4408
if (Left.is(TT_ArrayInitializerLSquare) && Left.is(tok::l_square) &&
!Right.is(tok::r_square)) {
- return true;
+ if (Right.is(tok::l_brace))
+ return true;
----------------
owenpan wrote:
> Merge the check for `comma` below to avoid repeated code. Also, the check for `l_brace` is redundant.
@owenpan you have a very fine eye.. I didn't see that and had to reread your comments a couple of times! Thank you its much cleaner now
================
Comment at: clang/lib/Format/TokenAnnotator.cpp:4427
+ if (Left.is(tok::comma)) {
+ if (Right.is(tok::l_brace)) {
+ return true;
----------------
curdeius wrote:
> You can elide braces here.
This was funny I had RemoveBracesLLVM on, but it didn't get rid of them automatically, I wonder if this was my fault or if we are missing a case for the RemoveBraces option, but thanks you be done now
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D133589/new/
https://reviews.llvm.org/D133589
More information about the cfe-commits
mailing list