This is an archive of the discontinued LLVM Phabricator instance.

[clang-format] JSON Add ability to add a space before the colon
ClosedPublic

Authored by MyDeveloperDay on Mar 27 2023, 2:32 PM.

Details

Summary

I've seen a couple of request for extra Json formatting to match prettier capability.

This patch allows for a space between the "key" and the colon

{
    "A" : "value"
}

Diff Detail

Event Timeline

MyDeveloperDay created this revision.Mar 27 2023, 2:32 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 27 2023, 2:32 PM
MyDeveloperDay requested review of this revision.Mar 27 2023, 2:32 PM

You need to add CHECK_PARSE_BOOL(SpaceBeforeJsonColon) in ConfigParseTest.cpp.

clang/include/clang/Format/Format.h
3717
clang/lib/Format/TokenAnnotator.cpp
4154–4155

Do we need to check if Left.is(tok::string_literal)?

MyDeveloperDay marked an inline comment as done.Mar 28 2023, 12:37 AM
MyDeveloperDay added inline comments.
clang/lib/Format/TokenAnnotator.cpp
4154–4155

Hmm... maybe... I guess I was thinking all colons in JSON are to the right of string literals?

MyDeveloperDay planned changes to this revision.Mar 28 2023, 12:40 AM
MyDeveloperDay marked an inline comment as done.
owenpan added inline comments.Mar 28 2023, 1:36 AM
clang/lib/Format/TokenAnnotator.cpp
4154–4155

I think you're right. Please ignore my comment then, or maybe add an assertion if you like.

MyDeveloperDay marked 2 inline comments as done.

add missing unit test
let's go defensive on the JsColon detection

clang/lib/Format/TokenAnnotator.cpp
4154–4155

you know what you pursued me lets go defensive and check anyway. Just incase an IDE is in the middle of editing when a save occurs.

owenpan accepted this revision.Mar 29 2023, 1:08 PM
This revision is now accepted and ready to land.Mar 29 2023, 1:08 PM
This revision was landed with ongoing or failed builds.Mar 29 2023, 1:29 PM
This revision was automatically updated to reflect the committed changes.