From 9ef45155dde9be2c5571e222a937285622983d79 Mon Sep 17 00:00:00 2001 From: csh Date: Wed, 29 Jul 2026 10:19:09 +0800 Subject: [PATCH] :wrench: chore(cpp): trim clang-format to intentional google deviations - keep only the options that differ from Google style, each annotated with the Google default, so every override carries its own rationale - switch to Allman braces and a 120 column limit; short functions now collapse only when declared inline - dropped overrides fall back to Google behaviour, which turns include sorting, argument binpacking, comment reflow and namespace comment fixing back on - drop a stray trailing blank line in .clangd --- templates/cpp/.clang-format | 50 ++++++------------------------------- templates/cpp/.clangd | 1 - 2 files changed, 7 insertions(+), 44 deletions(-) diff --git a/templates/cpp/.clang-format b/templates/cpp/.clang-format index c1928399..8536f783 100644 --- a/templates/cpp/.clang-format +++ b/templates/cpp/.clang-format @@ -2,46 +2,10 @@ Language: Cpp BasedOnStyle: Google -# Keep consistent with the repo-wide 100 char guidance (adjust per-project if needed). -ColumnLimit: 100 -IndentWidth: 4 - -AccessModifierOffset: -4 -AlignEscapedNewlines: Left -AlignTrailingComments: false -AllowAllParametersOfDeclarationOnNextLine: false -AllowShortFunctionsOnASingleLine: All -AlwaysBreakTemplateDeclarations: Yes -BinPackArguments: false -BinPackParameters: false -BraceWrapping: - AfterCaseLabel: true - AfterUnion: true - AfterExternBlock: false -BreakBeforeTernaryOperators: false -BreakConstructorInitializers: AfterColon -BreakInheritanceList: AfterColon -CommentPragmas: "suppress" -ConstructorInitializerAllOnOneLineOrOnePerLine: true -Cpp11BracedListStyle: false -FixNamespaceComments: false -IncludeBlocks: Regroup -IncludeCategories: - - Regex: '^.*(precomp|pch|stdafx)' - Priority: -1 - - Regex: '^".*"' - Priority: 1 - - Regex: '^<.*>' - Priority: 2 - - Regex: '.*' - Priority: 3 -KeepEmptyLinesAtTheStartOfBlocks: false -MacroBlockBegin: "BEGIN_TEST_METHOD_PROPERTIES|BEGIN_MODULE|BEGIN_TEST_CLASS|BEGIN_TEST_METHOD" -MacroBlockEnd: "END_TEST_METHOD_PROPERTIES|END_MODULE|END_TEST_CLASS|END_TEST_METHOD" -NamespaceIndentation: None -PointerAlignment: Left -ReflowComments: false -SortIncludes: false -SpaceAfterTemplateKeyword: false -SpacesInAngles: false -SpacesInContainerLiterals: false +# --- intentional deviations from Google C++ defaults --- +ColumnLimit: 120 # Google: 80 +IndentWidth: 4 # Google: 2 +TabWidth: 4 # Google/LLVM: 8(UseTab: Never 时几乎无感,与缩进对齐) +AccessModifierOffset: -4 # Google: -1(配合 IndentWidth 4,使 public/private 与 class 同级) +BreakBeforeBraces: Allman # Google: Attach +AllowShortFunctionsOnASingleLine: Inline # 需要显示Inline diff --git a/templates/cpp/.clangd b/templates/cpp/.clangd index be8b66f2..3a06649b 100644 --- a/templates/cpp/.clangd +++ b/templates/cpp/.clangd @@ -22,4 +22,3 @@ CompileFlags: Add: - "-std=c17" Compiler: clang -