关于clang-format合适代码风格调整

#### 参考网址:https://clang.llvm.org/docs/ClangFormatStyleOptions.html

BasedOnStyle : Microsoft 

# 支持的语言
# None, Cpp, CSharp, Java, JaveScript, Json, Objc, Proto, TableGen, TextProto
Language : Cpp
# 支持的c++标准:c++03, c++11, c++14, c++17, c++20, Latest, Auto
Standard : c++11
# table 缩进大小
IndentWidth : 4
TabWidth : 4
UseTab : ForIndentation
# 换行使用\r\n
UseCRLF : true


AlignAfterOpenBracket : Align
AlignArrayOfStructures : Left
AlignConsecutiveAssignments : Consecutive 
AlignConsecutiveBitFields : Consecutive 
AlignConsecutiveDeclarations : false
AlignConsecutiveMacros : Consecutive 
AlignEscapedNewlines : Left
AlignOperands : Align
AlignTrailingComments : true
AllowAllArgumentsOnNextLine : false
AllowAllParametersOfDeclarationOnNextLine : false
AllowShortBlocksOnASingleLine : Empty
AllowShortCaseLabelsOnASingleLine : true
AllowShortEnumsOnASingleLine : true
AllowShortFunctionsOnASingleLine : Empty
AllowShortIfStatementsOnASingleLine : Never
AllowShortLambdasOnASingleLine : Empty
AllowShortLoopsOnASingleLine : false
AlwaysBreakAfterReturnType : None
AlwaysBreakBeforeMultilineStrings : false
AlwaysBreakTemplateDeclarations : Yes
BinPackArguments : false
BinPackParameters : false
BitFieldColonSpacing : Both

BreakBeforeBraces: Custom
BraceWrapping :
  AfterCaseLabel : false
  AfterClass : true
  AfterControlStatement : Never
  AfterEnum: false
  AfterFunction : true
  AfterNamespace : false
  AfterStruct: false
  AfterUnion : false
  AfterExternBlock : true
  BeforeCatch : true
  BeforeElse : true
  BeforeLambdaBody : false
  BeforeWhile : false
  SplitEmptyFunction: false
  SplitEmptyRecord : false
  SplitEmptyNamespace : false

BreakBeforeBinaryOperators : None
BreakBeforeTernaryOperators : false
BreakStringLiterals : true
ColumnLimit : 80
ContinuationIndentWidth : 4
EmptyLineAfterAccessModifier : Leave
EmptyLineBeforeAccessModifier : LogicalBlock

# ForEachMacros: ['RANGES_FOR', 'FOREACH', 'BOOST_FOREACH']
# IfMacros: ['IF']
IncludeBlocks : Regroup
IncludeCategories:
  - Regex:           '^"(llvm|llvm-c|clang|clang-c)/'
    Priority:        2
    SortPriority:    2
    CaseSensitive:   true
  - Regex:           '^((<|")(gtest|gmock|isl|json)/)'
    Priority:        3
  - Regex:           '<[[:alnum:].]+>'
    Priority:        4
  - Regex:           '.*'
    Priority:        1
    SortPriority:    0

IndentAccessModifiers : true
IndentCaseBlocks : true
IndentCaseLabels : false
IndentGotoLabels : true
IndentPPDirectives : BeforeHash
IndentWrappedFunctionNames : true
KeepEmptyLinesAtTheStartOfBlocks : false
# # MacroBlockBegin: "^NS_MAP_BEGIN|\
# # NS_TABLE_HEAD$"
# # MacroBlockEnd: "^\
# # NS_MAP_END|\
# # NS_TABLE_.*_END$"

PenaltyBreakAssignment : 1
PenaltyBreakBeforeFirstCallParameter : 1
PenaltyBreakComment : 1
PenaltyBreakFirstLessLess : 1
PenaltyBreakOpenParenthesis : 1
PenaltyBreakString : 0
PenaltyBreakTemplateDeclaration : 1
PenaltyExcessCharacter : 0
PenaltyIndentedWhitespace : 4
PenaltyReturnTypeOnItsOwnLine : 1
PointerAlignment : Left

# # RawStringFormats:
# #   - Language: TextProto
# #       Delimiters:
# #         - 'pb'
# #         - 'proto'
# #       EnclosingFunctions:
# #         - 'PARSE_TEXT_PROTO'
# #       BasedOnStyle: google
# #   - Language: Cpp
# #       Delimiters:
# #         - 'cc'
# #         - 'cpp'
# #       BasedOnStyle: llvm
# #       CanonicalDelimiter: 'cc'


ReflowComments : true
SpaceAfterCStyleCast : false
SpaceAfterLogicalNot : false
SpaceAroundPointerQualifiers : Default
SpaceBeforeAssignmentOperators : true
SpaceBeforeCaseColon : false
SpaceBeforeSquareBrackets : false
SpaceInEmptyBlock : false
SpaceInEmptyParentheses : false
SpacesBeforeTrailingComments : 4
SpacesInCStyleCastParentheses : false
SpacesInContainerLiterals : false

生成后的效果如下所示

/**
 * @file exercise_4.c
 * @brief
 * @author 
 * @version 0.0.1
 * @date 2021-11-20
 *
 * @copyright Copyright (c) 2021
 *
 * @par 修改日志
 * <table>
 * <tr><th>Date       <th>Version <th>Author  <th>Description
 * <tr><td>2021-11-20 <td>0.0.1   <td>        <td>首版程序
 * </table>
 */
#include "common_yaq.h"    //!< 表示先从项目所在位置查找,找不到在从系统指定位置查找

#include <ctype.h>
#include <math.h>    //!< 表示从系统指定位置查找
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void test_0(void)
{       
  for (uint8_t i = 0; i < 10; i++) {
    printf("%d ", i);
  }

  while (FALSE) {
    int formak;    // test
  }

  printf("\r\n");
}
void test_1(void) {}

void test_2(void) {}
void test_3(void) {}

void test_4(void) {}

void test_5(void) {}

void test_6(void) {}

int32_t main(int32_t argc, char* argv[])
{
	test_0();
	/* 第一 */
	// test_1();
	//第二
	// printf("======== 2 =========\r\n");
	// test_2();
	/* 第三 */
	// printf("======== 3 =========\r\n");
	// test_3();
	/* 第四 */
	// printf("======== 4 =========\r\n");
	// test_4();
	/* 第五 */
	// printf("======== 5 =========\r\n");
	// test_5();
	/* 第六 */
	// printf("======== 6 =========\r\n");
	// test_6();

	return 0;
}

但是table键的缩进明明设置为4了,但实际上还是2,还不清楚什么原因,先保存再次,方便以后在使用

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Clang-Format提供了多种代码风格选项,可以根据具体需求选择合适风格。常见的一些代码风格选项包括: 1. Google风格:这是谷歌公司使用的代码风格,它强调代码的可读性和一致性。它使用4个空格缩进,函数名称使用小写字母和下划线,类名使用大写字母开头等。 2. Chromium风格:这是谷歌Chrome团队使用的代码风格,它在Google风格的基础上做了一些自定义修改。 3. LLVM风格:这是LLVM项目使用的代码风格,它强调代码的可读性、简洁性和一致性。它使用2个空格缩进,函数名称使用小写字母和下划线,类名使用大写字母开头等。 4. Mozilla风格:这是Mozilla项目使用的代码风格,它强调代码的可读性、简洁性和一致性。它使用2个空格缩进,函数名称使用小写字母和下划线,类名使用大写字母开头等。 5. WebKit风格:这是WebKit项目使用的代码风格,它强调代码的可读性和一致性。它使用2个空格缩进,函数名称使用小写字母和下划线,类名使用大写字母开头等。 此外,Clang-Format还支持自定义风格,可以通过编写.clang-format文件来定义自己的代码风格。 总结来说,Clang-Format提供了多种代码风格选项,包括Google、Chromium、LLVM、Mozilla和WebKit等,同时也支持自定义风格。具体选择哪种风格取决于个人或团队的需求和偏好。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [VS2019使用clang-format实现源代码格式化排版,解决“No Target Architecture”问题](https://blog.csdn.net/libaineu2004/article/details/112760035)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *3* [.clang-format](https://download.csdn.net/download/misslong/11615479)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值