This is an archive of the discontinued LLVM Phabricator instance.

[clang-format] Add a default format style that can be used by users of `getStyle`
ClosedPublic

Authored by ioeric on Jun 22 2018, 10:31 AM.

Details

Summary

Tools that reformat code often call getStyle to decide the format style
to use on a certain source file. In practice, "file" style is widely used. As a
result, many tools hardcode "file" when calling getStyle, which makes it hard
to control the default style in tools across a codebase when needed. This change
introduces a DefaultFormatStyle constant (default to "file" in upstream), which
can be modified downstream if wanted, so that all users/tools built from the same
source tree can have a consistent default format style.

This also adds an DefaultFallbackStyle that is recommended to be used by tools and can be modified downstream.

Diff Detail

Repository
rL LLVM

Event Timeline

ioeric created this revision.Jun 22 2018, 10:31 AM
sammccall accepted this revision.Jun 22 2018, 12:43 PM

I think this should work great for us, and hopefully helps other downstream users too.

(@djasper: the plan is to introduce a new style name for our tweaked version of "file", and make it the default)

tools/clang-format/ClangFormat.cpp
67 ↗(On Diff #152509)

My only question is if we want to do the same with DefaultFallbackStyle.

Not because we have a use case for changing it right now, but because it's another string that callers of getStyle() have to hard-code. In our internal codebase, some pass "LLVM", some pass "Google", and some make it an option.

This revision is now accepted and ready to land.Jun 22 2018, 12:43 PM
ioeric updated this revision to Diff 152636.Jun 25 2018, 1:50 AM
ioeric marked an inline comment as done.
  • Add DefaultFallbackStyle
ioeric added inline comments.Jun 25 2018, 1:50 AM
tools/clang-format/ClangFormat.cpp
67 ↗(On Diff #152509)

Can't see a reason not to. This should help get rid of more hardcode.

ioeric edited the summary of this revision. (Show Details)Jun 25 2018, 1:51 AM
This revision was automatically updated to reflect the committed changes.