From 31417ccfcd4f61564157e942dc28c13d26ffa0c4 Mon Sep 17 00:00:00 2001 From: Jameson Nash Date: Tue, 26 Aug 2025 12:04:25 +0000 Subject: [PATCH] misc: add clang-format file --- .clang-format | 96 +++++++++++++++++++++++++++++++++++++++++++++++++++ include/uv.h | 2 ++ 2 files changed, 98 insertions(+) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 000000000..0c5271e08 --- /dev/null +++ b/.clang-format @@ -0,0 +1,96 @@ +# libuv .clang-format configuration +# Based on Google C/C++ Style Guide with libuv-specific adaptations + +BasedOnStyle: Google + +# Language and standard +Language: Cpp + +# Indentation and spacing (2 spaces, no tabs as per CONTRIBUTING.md) +IndentWidth: 2 +TabWidth: 2 +UseTab: Never +ContinuationIndentWidth: 4 +IndentCaseLabels: false + +# Line length (80 characters as per CONTRIBUTING.md) +ColumnLimit: 80 + +# Alignment and breaking +AlignAfterOpenBracket: Align +AlignConsecutiveAssignments: false +AlignConsecutiveDeclarations: false +AlignConsecutiveMacros: true +AlignEscapedNewlines: Right +AlignOperands: true +AlignTrailingComments: true +AllowAllArgumentsOnNextLine: false +AllowAllConstructorInitializersOnNextLine: false +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortBlocksOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: None +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false + +# Breaking and wrapping +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: false +BinPackArguments: false +BinPackParameters: false +BreakBeforeBinaryOperators: None +BreakBeforeBraces: Attach +Cpp11BracedListStyle: true +BreakBeforeTernaryOperators: true +BreakConstructorInitializers: BeforeColon +BreakStringLiterals: true + +# Spacing +SpaceAfterCStyleCast: true +SpaceBeforeAssignmentOperators: true +SpaceBeforeParens: ControlStatements +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 2 +SpacesInAngles: false +SpacesInCStyleCastParentheses: false +SpacesInContainerLiterals: true +SpacesInParentheses: false +SpacesInSquareBrackets: false + +# Pointers and references +PointerAlignment: Left +DerivePointerAlignment: false + +# Comments +ReflowComments: true + +# Includes +IncludeBlocks: Preserve +SortIncludes: false + +# Penalties for breaking (to control formatting decisions) +PenaltyBreakAssignment: 2 +PenaltyBreakBeforeFirstCallParameter: 1 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakString: 1000 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 200 + +# Macros and preprocessor +IndentPPDirectives: AfterHash +MacroBlockBegin: '' +MacroBlockEnd: '' + +# Enum and macro formatting +AllowShortEnumsOnASingleLine: false +SpaceBeforeSquareBrackets: false + +# Other formatting options +KeepEmptyLinesAtTheStartOfBlocks: false +MaxEmptyLinesToKeep: 2 +FixNamespaceComments: false + +# Function spacing: requiring 2 newlines before functions is not supported by clang-format tool automatically +SeparateDefinitionBlocks: Leave diff --git a/include/uv.h b/include/uv.h index f788c040f..fe0d8f619 100644 --- a/include/uv.h +++ b/include/uv.h @@ -206,6 +206,7 @@ typedef enum { UV_HANDLE_TYPE_MAX } uv_handle_type; +/* clang-format off */ typedef enum { UV_UNKNOWN_REQ = 0, #define XX(uc, lc) UV_##uc, @@ -214,6 +215,7 @@ typedef enum { UV_REQ_TYPE_PRIVATE UV_REQ_TYPE_MAX } uv_req_type; +/* clang-format on */ /* Handle types. */