# SPDX-FileCopyrightText: 2019 Project Quotient
# SPDX-License-Identifier: LGPL-2.1-only
#
# You may use this file under the terms of the LGPL-2.1 license
# See the file LICENSE from this package for details.

# This is the clang-format configuration style to be used by libQuotient.
# Inspired by:
# https://code.qt.io/cgit/qt/qt5.git/plain/_clang-format
# https://wiki.qt.io/Qt_Coding_Style
# https://wiki.qt.io/Coding_Conventions
# Further information: https://clang.llvm.org/docs/ClangFormatStyleOptions.html

# For convenience, the file includes commented out settings that we assume
# to borrow from the WebKit style. The values for such settings try to but
# are not guaranteed to coincide with the latest version of the WebKit style.

# This file assumes ClangFormat 18 or newer

---
Language: Cpp
BasedOnStyle: WebKit
#AccessModifierOffset: -4
AlignAfterOpenBracket: Align
#AlignArrayOfStructures: None # As of ClangFormat 14, Left doesn't work well
#AlignConsecutiveAssignments: None
#AlignConsecutiveDeclarations: None
#AlignConsecutiveMacros: None
AlignConsecutiveShortCaseStatements:
  Enabled: true
AlignEscapedNewlines: Left
AlignOperands: Align
#AlignTrailingComments: false
#AllowAllArgumentsOnNextLine: true
#AllowAllParametersOfDeclarationOnNextLine: true
AllowBreakBeforeNoexceptSpecifier: Always
AllowShortBlocksOnASingleLine: Empty
AllowShortCaseLabelsOnASingleLine: true
#AllowShortCompoundRequirementOnASingleLine: true
#AllowShortEnumsOnASingleLine: true
#AllowShortFunctionsOnASingleLine: All
#AllowShortIfStatementsOnASingleLine: Never
#AllowShortLambdasOnASingleLine: All
#AllowShortLoopsOnASingleLine: false
#AlwaysBreakAfterReturnType: None
#AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: Yes # To be replaced with BreakTemplateDeclarations
AttributeMacros:
  - Q_IMPLICIT
#BinPackArguments: true
#BinPackParameters: true
#BitFieldColonSpacing: Both
BraceWrapping:
#  AfterCaseLabel:  false
#  AfterClass:      false
#  AfterControlStatement: Never
#  AfterEnum:       false
#  AfterExternBlock: false
  AfterFunction:   true
#  AfterNamespace:  false
#  AfterStruct:     false
#  AfterUnion:      false
#  BeforeCatch:     false
#  BeforeElse:      false
  BeforeLambdaBody: true
#  BeforeWhile:     false
#  IndentBraces:    false
  SplitEmptyFunction: false
  SplitEmptyRecord: false
  SplitEmptyNamespace: false
BracedInitializerIndentWidth: 2 # Initializer padding inhibits this, making indentation inconsistent
#BreakAdjacentStringLiterals: true
#BreakAfterAttributes: Leave
#BreakAfterReturnType: Automatic # ClangFormat 19; default value anyway
BreakBeforeBinaryOperators: NonAssignment
#BreakBeforeConceptDeclarations: Always
BreakBeforeBraces: Custom
#BreakBeforeTernaryOperators: true
#BreakConstructorInitializers: BeforeComma
#BreakFunctionDefinitionParameters: false # ClangFormat 19; default value anyway
#BreakInheritanceList: BeforeColon
#BreakStringLiterals: true
#BreakTemplateDeclarations: Multiline # As of ClangFormat 19, has unintended formatting side-effects
ColumnLimit: 100
#QualifierAlignment: Leave # ClangFormat 14 - except 'Leave', updates whole files
#CompactNamespaces: false
#ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 2
Cpp11BracedListStyle: true
#DerivePointerAlignment: false
#EmptyLineAfterAccessModifier: Never
EmptyLineBeforeAccessModifier: LogicalBlock
FixNamespaceComments: true
IncludeBlocks: Regroup
IncludeCategories:
  - Regex:    '["</](events|jobs)/'
    Priority: 8
  - Regex:    '["</]csapi/'
    Priority: 12
  - Regex:    '^["<](Quotient/)?.+\.h[">]'
    Priority: 16
  - Regex:    '^<Qt(Core|Network|Gui)/.+'
    Priority: 28
  - Regex:    '^<Qt.+(/.+)?'
    Priority: 24
  - Regex:    '^<'
    Priority: 32
  - Regex:    '.*'
    Priority: 1
IncludeIsMainRegex: '(_test)?$'
#IncludeIsMainSourceRegex: ''
#IndentAccessModifiers: false
#IndentCaseBlocks: false
#IndentCaseLabels: false
IndentExternBlock: AfterExternBlock
IndentGotoLabels: false
IndentPPDirectives: AfterHash
IndentRequiresClause: true
#IndentWidth: 4
#IndentWrappedFunctionNames: false
#InsertBraces: false # true is dangerous, see ClangFormat docs
InsertNewlineAtEOF: true
#InsertTrailingCommas: None # According to the docs, only available for JavaScript
IntegerLiteralSeparator:
  Binary:          4
  BinaryMinDigits: 5
  Decimal:         3
  DecimalMinDigits: 4
  Hex:             2
  HexMinDigits:    5
#KeepEmptyLines: # Uncomment the block once ClangFormat 19 is the baseline
#  AtEndOfFile:     true
#  AtStartOfBlock:  false
#  AtStartOfFile:   false
KeepEmptyLinesAtTheStartOfBlocks: false # To be replaced with KeepEmptyLines
LambdaBodyIndentation: OuterScope
LineEnding:      LF
#MacroBlockBegin: ''
#MacroBlockEnd:   ''
#MainIncludeChar: Quote
#MaxEmptyLinesToKeep: 1
#NamespaceIndentation: Inner
PackConstructorInitializers: NextLine
PenaltyBreakAssignment: 10
PenaltyBreakBeforeFirstCallParameter: 70
PenaltyBreakComment: 45
#PenaltyBreakFirstLessLess: 120
#PenaltyBreakOpenParenthesis: 0
#PenaltyBreakScopeResolution: 500
PenaltyBreakString: 200
#PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 40
#PenaltyIndentedWhitespace: 0
PenaltyReturnTypeOnItsOwnLine: 200
#PointerAlignment: Left
#PPIndentWidth: -1
#QualifierAlignment: Leave # Anything else is dangerous, see ClangFormat docs
#QualifierOrder: ['friend', 'static', 'inline', 'constexpr', 'const', 'volatile', 'type'] # Unknown key error, despite the documentation...
#ReferenceAlignment: Pointer
#ReflowComments: true
# Setting non-default values for Remove* options below is dangerous, check ClangFormat docs
#RemoveBracesLLVM: false
#RemoveParentheses: Leave
#RemoveSemicolon: false
#RequiresClausePosition: WithPreceding # As of ClangFormat 19, unindents requires-clause :(
#RequiresExpressionIndentation: OuterScope # No cases in the codebase so far
#SeparateDefinitionBlocks: Leave
ShortNamespaceLines: 20
#SkipMacroDefinitionBody: false
#SortIncludes: CaseSensitive
#SortUsingDeclarations: LexicographicNumeric
#SpaceAfterCStyleCast: false
#SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: false
SpaceAroundPointerQualifiers: After
#SpaceBeforeAssignmentOperators: true
#SpaceBeforeCaseColon: false
SpaceBeforeCpp11BracedList: false
#SpaceBeforeCtorInitializerColon: true
#SpaceBeforeInheritanceColon: true
SpaceBeforeParens: Custom
SpaceBeforeParensOptions:
#  AfterControlStatements: true
#  AfterForeachMacros: true
#  AfterFunctionDefinitionName: false
#  AfterFunctionDeclarationName: false
#  AfterIfMacros:   true
#  AfterOverloadedOperator: false
  AfterPlacementOperator: false
  AfterRequiresInClause: true
#  AfterRequiresInExpression: false
#  BeforeNonEmptyParentheses: false
#SpaceBeforeRangeBasedForLoopColon: true
#SpaceBeforeSquareBrackets: false
SpaceInEmptyBlock: false
#SpacesBeforeTrailingComments: 1
#SpacesInAngles: Never
#SpacesInContainerLiterals: true # Not relevant to C++?
#SpacesInLineCommentPrefix:
#  Minimum:         1
#  Maximum:         -1
#SpacesInParens:  Never
#SpacesInParensOptions:
#  ExceptDoubleParentheses: false
#  InCStyleCasts:   false
#  InConditionalStatements: false
#  InEmptyParentheses: false
#  Other:           false
#SpacesInSquareBrackets: false
Standard: c++20
StatementAttributeLikeMacros:
  - Q_EMIT
  - emit
StatementMacros:
  - Q_UNUSED
  - QT_REQUIRE_VERSION
TabWidth: 4
#UseTab: Never
#WhitespaceSensitiveMacros: [] # Whatever's the default, not using it
...

