diff options
author | Eric Liu <ioeric@google.com> | 2018-06-25 16:29:19 +0000 |
---|---|---|
committer | Eric Liu <ioeric@google.com> | 2018-06-25 16:29:19 +0000 |
commit | e0e097a759cc3c58306d8201dcc4e2f5fcc84e63 (patch) | |
tree | 0d354c7492685189b16d0d6068ca715f86777e05 /tools | |
parent | a605c7e73552ba349e2ceb5baa8daba92d9faf98 (diff) | |
download | clang-e0e097a759cc3c58306d8201dcc4e2f5fcc84e63.tar.gz |
[clang-format] Add a default format style that can be used by users of `getStyle`
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.
Reviewers: sammccall, djasper
Reviewed By: sammccall
Subscribers: cfe-commits
Differential Revision: https://reviews.llvm.org/D48492
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@335492 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools')
-rw-r--r-- | tools/clang-format/ClangFormat.cpp | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/tools/clang-format/ClangFormat.cpp b/tools/clang-format/ClangFormat.cpp index fdd0c41d08..de2f9d7fe7 100644 --- a/tools/clang-format/ClangFormat.cpp +++ b/tools/clang-format/ClangFormat.cpp @@ -60,17 +60,18 @@ LineRanges("lines", cl::desc("<start line>:<end line> - format a range of\n" "Can only be used with one input file."), cl::cat(ClangFormatCategory)); static cl::opt<std::string> - Style("style", - cl::desc(clang::format::StyleOptionHelpDescription), - cl::init("file"), cl::cat(ClangFormatCategory)); + Style("style", cl::desc(clang::format::StyleOptionHelpDescription), + cl::init(clang::format::DefaultFormatStyle), + cl::cat(ClangFormatCategory)); static cl::opt<std::string> -FallbackStyle("fallback-style", - cl::desc("The name of the predefined style used as a\n" - "fallback in case clang-format is invoked with\n" - "-style=file, but can not find the .clang-format\n" - "file to use.\n" - "Use -fallback-style=none to skip formatting."), - cl::init("LLVM"), cl::cat(ClangFormatCategory)); + FallbackStyle("fallback-style", + cl::desc("The name of the predefined style used as a\n" + "fallback in case clang-format is invoked with\n" + "-style=file, but can not find the .clang-format\n" + "file to use.\n" + "Use -fallback-style=none to skip formatting."), + cl::init(clang::format::DefaultFallbackStyle), + cl::cat(ClangFormatCategory)); static cl::opt<std::string> AssumeFileName("assume-filename", |