This is an archive of the discontinued LLVM Phabricator instance.

[clang-format] NFC Document the other space before colon option
ClosedPublic

Authored by sstwcw on Apr 2 2023, 8:54 PM.

Details

Summary

There are two options that do much the same thing, but for different
languages. With the addition to the doc, the user is less likely to
configure the wrong option and get frustrated that it doesn't work.

Diff Detail

Event Timeline

sstwcw created this revision.Apr 2 2023, 8:54 PM
Herald added projects: Restricted Project, Restricted Project, Restricted Project. · View Herald TranscriptApr 2 2023, 8:54 PM
sstwcw requested review of this revision.Apr 2 2023, 8:54 PM
NOTE: Clang-Format Team Automated Review Comment

It looks like your clang-format review does not contain any unit tests, please try to ensure all code changes have a unit test (unless this is an NFC or refactoring, adding documentation etc..)

Add you unit tests in clang/unittests/Format and build ninja FormatTests we recommend using the verifyFormat(xxx) format of unit tests rather than EXPECT_EQ as this will ensure you change is tolerant to random whitespace changes (see FormatTest.cpp as an example)

For situations where your change is altering the TokenAnnotator.cpp which can happen if you are trying to improve the annotation phase to ensure we are correctly identifying the type of a token, please add a token annotator test in TokenAnnotatorTest.cpp

MyDeveloperDay accepted this revision.Apr 3 2023, 12:13 AM
This revision is now accepted and ready to land.Apr 3 2023, 12:13 AM

Should we extend SpacesInContainerLiterals so that it controls JSON colons too? If yes, then we don't need SpaceBeforeJsonColon. Otherwise, IMO we should leave the doc alone.

Should we extend SpacesInContainerLiterals so that it controls JSON colons too? If yes, then we don't need SpaceBeforeJsonColon. Otherwise, IMO we should leave the doc alone.

My concern for SpacesInContainerLiterals is that it impacts arrays contents too '[ 1, 2, 3 ]'.

In D147422#4239701, @Herald wrote:
NOTE: Clang-Format Team Automated Review Comment

It looks like your clang-format review does not contain any unit tests, please try to ensure all code changes have a unit test (unless this is an NFC or refactoring, adding documentation etc..)

Add you unit tests in clang/unittests/Format and build ninja FormatTests we recommend using the verifyFormat(xxx) format of unit tests rather than EXPECT_EQ as this will ensure you change is tolerant to random whitespace changes (see FormatTest.cpp as an example)

For situations where your change is altering the TokenAnnotator.cpp which can happen if you are trying to improve the annotation phase to ensure we are correctly identifying the type of a token, please add a token annotator test in TokenAnnotatorTest.cpp

Thanks for testing this automated comment ;-) , I've fixed some of the grammatical issue and made it so it won't fire if NFC is in the title.

sstwcw added a comment.Apr 3 2023, 7:23 PM

Should we extend SpacesInContainerLiterals so that it controls JSON colons too? If yes, then we don't need SpaceBeforeJsonColon. Otherwise, IMO we should leave the doc alone.

My concern for SpacesInContainerLiterals is that it impacts arrays contents too '[ 1, 2, 3 ]'.

It looks like a line break gets inserted in arrays. Does that mean the option doesn't affect arrays?

Should we extend SpacesInContainerLiterals so that it controls JSON colons too? If yes, then we don't need SpaceBeforeJsonColon. Otherwise, IMO we should leave the doc alone.

My concern for SpacesInContainerLiterals is that it impacts arrays contents too '[ 1, 2, 3 ]'.

It already affects JSON arrays if BreakArrays is set to false:

$ cat foo.json
[1, 2, 3]
$ clang-format -style='{BreakArrays: false}' foo.json
[ 1, 2, 3 ]

It looks like a line break gets inserted in arrays. Does that mean the option doesn't affect arrays?

It matters only if BreakArrays is set to false.

This revision was landed with ongoing or failed builds.Apr 7 2023, 6:52 AM
This revision was automatically updated to reflect the committed changes.