Add C++ formatting configs (#4254)
This commit is contained in:
committed by
GitHub
parent
584262c83d
commit
d8056544e5
+194
@@ -0,0 +1,194 @@
|
|||||||
|
# Also see codestyle/cpp/README.md
|
||||||
|
# For documentation on options see: https://releases.llvm.org/8.0.0/tools/clang/docs/ClangFormatStyleOptions.html
|
||||||
|
# "Kt N/A" means that this C/C++/ObjC construct have no corresponding Kotlin construct to refer to
|
||||||
|
# "Kt U" means that formatting is unspecified in Kotlin formatting guide
|
||||||
|
# "Kt <url>" means that this is specified in Kotlin formatting guide with url pointing to it
|
||||||
|
---
|
||||||
|
DisableFormat: false
|
||||||
|
Standard: Cpp11
|
||||||
|
|
||||||
|
# Kt N/A. Different from 0 to make modifiers stand out. An alternative is -2, but it introduces another level of indentation.
|
||||||
|
AccessModifierOffset: -4
|
||||||
|
# Kt https://kotlinlang.org/docs/reference/coding-conventions.html#method-call-formatting
|
||||||
|
AlignAfterOpenBracket: AlwaysBreak
|
||||||
|
# Kt U. Not touching
|
||||||
|
AlignConsecutiveAssignments: false
|
||||||
|
# Kt U. Not touching
|
||||||
|
AlignConsecutiveDeclarations: false
|
||||||
|
# Kt N/A. Not touching
|
||||||
|
AlignEscapedNewlines: DontAlign
|
||||||
|
# Kt U. Not touching
|
||||||
|
AlignOperands: false
|
||||||
|
# Kt U. Not touching
|
||||||
|
AlignTrailingComments: false
|
||||||
|
# Kt https://kotlinlang.org/docs/reference/coding-conventions.html#function-formatting
|
||||||
|
AllowAllParametersOfDeclarationOnNextLine: true
|
||||||
|
# Kt https://kotlinlang.org/docs/reference/coding-conventions.html#formatting-control-flow-statements
|
||||||
|
AllowShortBlocksOnASingleLine: false
|
||||||
|
# Kt U. The closest is https://kotlinlang.org/docs/reference/coding-conventions.html#formatting-control-flow-statements
|
||||||
|
# Using false, because case statements usually contain at least 2 statements: doing something + break, which makes them multiline
|
||||||
|
AllowShortCaseLabelsOnASingleLine: false
|
||||||
|
# Kt https://kotlinlang.org/docs/reference/coding-conventions.html#function-formatting Inline is somewhat close to "single expression" functions
|
||||||
|
AllowShortFunctionsOnASingleLine: Inline
|
||||||
|
# Kt U. The closest is https://kotlinlang.org/docs/reference/coding-conventions.html#using-conditional-statements however it mostly refers to the ternary operator.
|
||||||
|
AllowShortIfStatementsOnASingleLine: true
|
||||||
|
# Kt U. Same as previous
|
||||||
|
AllowShortLoopsOnASingleLine: true
|
||||||
|
# Kt N/A. In Kotlin return type is in a trailing position.
|
||||||
|
AlwaysBreakAfterReturnType: None
|
||||||
|
# Kt U. Not touching.
|
||||||
|
AlwaysBreakBeforeMultilineStrings: false
|
||||||
|
# Kt N/A. In Kotlin type parameters are declared inline in a much more compact way.
|
||||||
|
# Using Yes to make it easy to detect function name
|
||||||
|
AlwaysBreakTemplateDeclarations: Yes
|
||||||
|
# Kt https://kotlinlang.org/docs/reference/coding-conventions.html#method-call-formatting
|
||||||
|
BinPackArguments: true
|
||||||
|
# Kt https://kotlinlang.org/docs/reference/coding-conventions.html#function-formatting
|
||||||
|
BinPackParameters: false
|
||||||
|
BraceWrapping:
|
||||||
|
# Kt https://kotlinlang.org/docs/reference/coding-conventions.html#formatting
|
||||||
|
AfterClass: false
|
||||||
|
# Kt https://kotlinlang.org/docs/reference/coding-conventions.html#formatting
|
||||||
|
AfterControlStatement: false
|
||||||
|
# Kt https://kotlinlang.org/docs/reference/coding-conventions.html#formatting
|
||||||
|
AfterEnum: false
|
||||||
|
# Kt https://kotlinlang.org/docs/reference/coding-conventions.html#formatting
|
||||||
|
AfterFunction: false
|
||||||
|
# Kt https://kotlinlang.org/docs/reference/coding-conventions.html#formatting
|
||||||
|
AfterNamespace: false
|
||||||
|
# Kt https://kotlinlang.org/docs/reference/coding-conventions.html#formatting
|
||||||
|
AfterObjCDeclaration: false
|
||||||
|
# Kt https://kotlinlang.org/docs/reference/coding-conventions.html#formatting
|
||||||
|
AfterStruct: false
|
||||||
|
# Kt https://kotlinlang.org/docs/reference/coding-conventions.html#formatting
|
||||||
|
AfterUnion: false
|
||||||
|
# Kt https://kotlinlang.org/docs/reference/coding-conventions.html#formatting
|
||||||
|
AfterExternBlock: false
|
||||||
|
# Kt https://kotlinlang.org/docs/reference/coding-conventions.html#formatting-control-flow-statements
|
||||||
|
BeforeCatch: false
|
||||||
|
# Kt https://kotlinlang.org/docs/reference/coding-conventions.html#formatting-control-flow-statements
|
||||||
|
BeforeElse: false
|
||||||
|
# Kt https://kotlinlang.org/docs/reference/coding-conventions.html#formatting
|
||||||
|
IndentBraces: false
|
||||||
|
# Only used when AfterFunction is true
|
||||||
|
SplitEmptyFunction: true
|
||||||
|
# Only used when AfterRecord is true
|
||||||
|
SplitEmptyRecord: true
|
||||||
|
# Only used if AfterNamespace is true
|
||||||
|
SplitEmptyNamespace: true
|
||||||
|
# Kt U. Break after operators
|
||||||
|
BreakBeforeBinaryOperators: None
|
||||||
|
# Configured by BraceWrapping
|
||||||
|
BreakBeforeBraces: Custom
|
||||||
|
# Kt U. Using true because it looks more like an if-expression with "then" and "else" branches marked "?" and ":"
|
||||||
|
BreakBeforeTernaryOperators: true
|
||||||
|
# Kt N/A. The closest is https://kotlinlang.org/docs/reference/coding-conventions.html#class-header-formatting AfterColon looks the most consistent
|
||||||
|
BreakConstructorInitializers: AfterColon
|
||||||
|
# Kt https://kotlinlang.org/docs/reference/coding-conventions.html#class-header-formatting
|
||||||
|
BreakInheritanceList: AfterColon
|
||||||
|
# Kt U. Choosing to break long strings to fit into line length
|
||||||
|
BreakStringLiterals: true
|
||||||
|
# Kt U. IDEA displays a vertical guide at 120. Choosing it to avoid very long lines.
|
||||||
|
ColumnLimit: 140
|
||||||
|
# Kt N/A. Probably should use nested namespaces instead.
|
||||||
|
CompactNamespaces: false
|
||||||
|
# Kt N/A. The closest is https://kotlinlang.org/docs/reference/coding-conventions.html#class-header-formatting
|
||||||
|
ConstructorInitializerAllOnOneLineOrOnePerLine: true
|
||||||
|
# Kt https://kotlinlang.org/docs/reference/coding-conventions.html#formatting
|
||||||
|
ConstructorInitializerIndentWidth: 4
|
||||||
|
# Kt https://kotlinlang.org/docs/reference/coding-conventions.html#formatting IDEA seems to indent continuations with 8
|
||||||
|
ContinuationIndentWidth: 8
|
||||||
|
# Kt N/A. The closest is https://kotlinlang.org/docs/reference/coding-conventions.html#horizontal-whitespace
|
||||||
|
# Braced initalizer braces are close to parens in function call or to brackets in array initialier. And styleguide asks not to put spaces in them.
|
||||||
|
Cpp11BracedListStyle: true
|
||||||
|
# Configured by PointerAlignment
|
||||||
|
DerivePointerAlignment: false
|
||||||
|
# Confgured by BinPack*
|
||||||
|
ExperimentalAutoDetectBinPacking: false
|
||||||
|
# Kt N/A. Setting to true because it helps to see when anonymous namespace ends
|
||||||
|
FixNamespaceComments: true
|
||||||
|
# Kt U. Not touching manually created including blocks
|
||||||
|
IncludeBlocks: Preserve
|
||||||
|
# Kt U. Sorting: main header (priority 0) > system headers > project headers
|
||||||
|
IncludeCategories:
|
||||||
|
- Regex: '^<.*'
|
||||||
|
Priority: 1
|
||||||
|
- Regex: '.*'
|
||||||
|
Priority: 2
|
||||||
|
# Kt N/A. Main header must match current filename (modulo extension) exactly.
|
||||||
|
IncludeIsMainRegex: '$'
|
||||||
|
# Kt https://kotlinlang.org/docs/reference/coding-conventions.html#formatting-control-flow-statements
|
||||||
|
IndentCaseLabels: true
|
||||||
|
# Kt N/A. Do not indent macro code
|
||||||
|
IndentPPDirectives: None
|
||||||
|
# Kt https://kotlinlang.org/docs/reference/coding-conventions.html#formatting
|
||||||
|
IndentWidth: 4
|
||||||
|
# Kt U. IDEA seems to indent
|
||||||
|
IndentWrappedFunctionNames: true
|
||||||
|
# Kt U. Do not touch.
|
||||||
|
KeepEmptyLinesAtTheStartOfBlocks: false
|
||||||
|
# Kt U. IDEA keeps 1 empty line by default.
|
||||||
|
MaxEmptyLinesToKeep: 1
|
||||||
|
# Kt N/A.
|
||||||
|
NamespaceIndentation: None
|
||||||
|
# Kt N/A. The closest is https://kotlinlang.org/docs/reference/coding-conventions.html#class-header-formatting
|
||||||
|
ObjCBinPackProtocolList: Never
|
||||||
|
# Kt https://kotlinlang.org/docs/reference/coding-conventions.html#formatting
|
||||||
|
ObjCBlockIndentWidth: 4
|
||||||
|
# Kt N/A. Following Google and LLVM styleguides.
|
||||||
|
ObjCSpaceAfterProperty: false
|
||||||
|
# Kt N/A. The closest is class inheritance list. Following Google and LLVM styleguides.
|
||||||
|
ObjCSpaceBeforeProtocolList: true
|
||||||
|
# Kt N/A.
|
||||||
|
PointerAlignment: Left
|
||||||
|
# Kt U. Reflow comments to fit into line width
|
||||||
|
ReflowComments: true
|
||||||
|
# Kt U. IDEA does not sort by default, but allows this option. Do not touch.
|
||||||
|
SortIncludes: false
|
||||||
|
# Kt U. Like SortIncludes.
|
||||||
|
SortUsingDeclarations: false
|
||||||
|
# Kt N/A.
|
||||||
|
SpaceAfterCStyleCast: false
|
||||||
|
# Kt N/A. IDEA puts space in `fun <T>`
|
||||||
|
SpaceAfterTemplateKeyword: true
|
||||||
|
# Kt U. https://kotlinlang.org/docs/reference/coding-conventions.html puts spaces
|
||||||
|
SpaceBeforeAssignmentOperators: true
|
||||||
|
# Kt N/A. The closest is https://kotlinlang.org/docs/reference/coding-conventions.html#horizontal-whitespace which does not put space before parens and brackets.
|
||||||
|
SpaceBeforeCpp11BracedList: false
|
||||||
|
# Kt N/A. The closest is https://kotlinlang.org/docs/reference/coding-conventions.html#colon
|
||||||
|
SpaceBeforeCtorInitializerColon: true
|
||||||
|
# Kt https://kotlinlang.org/docs/reference/coding-conventions.html#colon
|
||||||
|
SpaceBeforeInheritanceColon: true
|
||||||
|
# Kt https://kotlinlang.org/docs/reference/coding-conventions.html#horizontal-whitespace
|
||||||
|
SpaceBeforeParens: ControlStatements
|
||||||
|
# Kt https://kotlinlang.org/docs/reference/coding-conventions.html#horizontal-whitespace
|
||||||
|
SpaceBeforeRangeBasedForLoopColon: true
|
||||||
|
# Kt https://kotlinlang.org/docs/reference/coding-conventions.html#horizontal-whitespace
|
||||||
|
SpaceInEmptyParentheses: false
|
||||||
|
# Kt U. https://kotlinlang.org/docs/reference/coding-conventions.html uses 1
|
||||||
|
SpacesBeforeTrailingComments: 1
|
||||||
|
# Kt https://kotlinlang.org/docs/reference/coding-conventions.html#horizontal-whitespace
|
||||||
|
SpacesInAngles: false
|
||||||
|
# Kt https://kotlinlang.org/docs/reference/coding-conventions.html#horizontal-whitespace
|
||||||
|
SpacesInContainerLiterals: false
|
||||||
|
# Kt N/A.
|
||||||
|
SpacesInCStyleCastParentheses: false
|
||||||
|
# Kt https://kotlinlang.org/docs/reference/coding-conventions.html#horizontal-whitespace
|
||||||
|
SpacesInParentheses: false
|
||||||
|
# Kt https://kotlinlang.org/docs/reference/coding-conventions.html#horizontal-whitespace
|
||||||
|
SpacesInSquareBrackets: false
|
||||||
|
# Kt https://kotlinlang.org/docs/reference/coding-conventions.html#formatting
|
||||||
|
TabWidth: 4
|
||||||
|
# Kt https://kotlinlang.org/docs/reference/coding-conventions.html#formatting
|
||||||
|
UseTab: Never
|
||||||
|
|
||||||
|
PenaltyBreakAssignment: 2
|
||||||
|
PenaltyBreakBeforeFirstCallParameter: 1
|
||||||
|
PenaltyBreakComment: 300
|
||||||
|
PenaltyBreakFirstLessLess: 120
|
||||||
|
PenaltyBreakString: 1000
|
||||||
|
PenaltyBreakTemplateDeclaration: 10
|
||||||
|
PenaltyExcessCharacter: 1000000
|
||||||
|
PenaltyReturnTypeOnItsOwnLine: 200
|
||||||
|
...
|
||||||
|
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
<code_scheme name="Project" version="173">
|
||||||
|
<option name="AUTODETECT_INDENTS" value="false" />
|
||||||
|
<Objective-C>
|
||||||
|
<option name="INDENT_NAMESPACE_MEMBERS" value="0" />
|
||||||
|
<option name="KEEP_STRUCTURES_IN_ONE_LINE" value="true" />
|
||||||
|
<option name="KEEP_CASE_EXPRESSIONS_IN_ONE_LINE" value="true" />
|
||||||
|
<option name="KEEP_NESTED_NAMESPACES_IN_ONE_LINE" value="true" />
|
||||||
|
<option name="FUNCTION_NON_TOP_AFTER_RETURN_TYPE_WRAP" value="0" />
|
||||||
|
<option name="FUNCTION_TOP_AFTER_RETURN_TYPE_WRAP" value="0" />
|
||||||
|
<option name="FUNCTION_PARAMETERS_WRAP" value="5" />
|
||||||
|
<option name="FUNCTION_CALL_ARGUMENTS_WRAP" value="5" />
|
||||||
|
<option name="TEMPLATE_CALL_ARGUMENTS_WRAP" value="5" />
|
||||||
|
<option name="TEMPLATE_CALL_ARGUMENTS_ALIGN_MULTILINE" value="true" />
|
||||||
|
<option name="CLASS_CONSTRUCTOR_INIT_LIST_WRAP" value="5" />
|
||||||
|
<option name="SPACE_BEFORE_TEMPLATE_DECLARATION_LT" value="true" />
|
||||||
|
<option name="ALIGN_INIT_LIST_IN_COLUMNS" value="false" />
|
||||||
|
<option name="SPACE_BEFORE_PROTOCOLS_BRACKETS" value="false" />
|
||||||
|
<option name="SPACE_BEFORE_POINTER_IN_DECLARATION" value="false" />
|
||||||
|
<option name="SPACE_AFTER_POINTER_IN_DECLARATION" value="true" />
|
||||||
|
<option name="SPACE_BEFORE_REFERENCE_IN_DECLARATION" value="false" />
|
||||||
|
<option name="SPACE_AFTER_REFERENCE_IN_DECLARATION" value="true" />
|
||||||
|
<option name="KEEP_BLANK_LINES_BEFORE_END" value="1" />
|
||||||
|
</Objective-C>
|
||||||
|
<Objective-C-extensions>
|
||||||
|
<extensions>
|
||||||
|
<pair source="cpp" header="hpp" fileNamingConvention="NONE" />
|
||||||
|
<pair source="c" header="h" fileNamingConvention="NONE" />
|
||||||
|
</extensions>
|
||||||
|
<rules>
|
||||||
|
<rule entity="MACRO" visibility="ANY" specifier="ANY" prefix="" style="SCREAMING_SNAKE_CASE" suffix="" />
|
||||||
|
<rule entity="NAMESPACE" visibility="ANY" specifier="ANY" prefix="" style="SNAKE_CASE" suffix="" />
|
||||||
|
<rule entity="CLASS,ENUM,UNION,TYPEDEF" visibility="ANY" specifier="ANY" prefix="" style="PASCAL_CASE" suffix="" />
|
||||||
|
<rule entity="CLASS_MEMBER_FIELD" visibility="ANY" specifier="ANY" prefix="" style="CAMEL_CASE" suffix="" />
|
||||||
|
<rule entity="STRUCT_MEMBER_FIELD" visibility="ANY" specifier="ANY" prefix="" style="CAMEL_CASE" suffix="" />
|
||||||
|
<rule entity="ENUMERATOR" visibility="ANY" specifier="ANY" prefix="" style="SCREAMING_SNAKE_CASE" suffix="" />
|
||||||
|
<rule entity="GLOBAL_FUNCTION,CLASS_MEMBER_FUNCTION,STRUCT_MEMBER_FUNCTION" visibility="ANY" specifier="ANY" prefix="" style="PASCAL_CASE" suffix="" />
|
||||||
|
<rule entity="PARAMETER,LOCAL_VARIABLE" visibility="ANY" specifier="ANY" prefix="" style="CAMEL_CASE" suffix="" />
|
||||||
|
<rule entity="GLOBAL_VARIABLE,LOCAL_VARIABLE" visibility="ANY" specifier="CONST" prefix="k" style="PASCAL_CASE" suffix="" />
|
||||||
|
<rule entity="CLASS_MEMBER_FIELD" visibility="PRIVATE" specifier="ANY" prefix="" style="CAMEL_CASE" suffix="_" />
|
||||||
|
</rules>
|
||||||
|
</Objective-C-extensions>
|
||||||
|
<codeStyleSettings language="ObjectiveC">
|
||||||
|
<option name="KEEP_BLANK_LINES_IN_DECLARATIONS" value="10" />
|
||||||
|
<option name="KEEP_BLANK_LINES_IN_CODE" value="10" />
|
||||||
|
<option name="KEEP_BLANK_LINES_BEFORE_RBRACE" value="10" />
|
||||||
|
<option name="BLANK_LINES_BEFORE_IMPORTS" value="0" />
|
||||||
|
<option name="BLANK_LINES_AFTER_IMPORTS" value="0" />
|
||||||
|
<option name="BLANK_LINES_AROUND_CLASS" value="0" />
|
||||||
|
<option name="BLANK_LINES_AROUND_METHOD" value="0" />
|
||||||
|
<option name="BLANK_LINES_AROUND_METHOD_IN_INTERFACE" value="0" />
|
||||||
|
<option name="ALIGN_MULTILINE_BINARY_OPERATION" value="false" />
|
||||||
|
<option name="BINARY_OPERATION_SIGN_ON_NEXT_LINE" value="true" />
|
||||||
|
<option name="FOR_STATEMENT_WRAP" value="1" />
|
||||||
|
<option name="ASSIGNMENT_WRAP" value="1" />
|
||||||
|
</codeStyleSettings>
|
||||||
|
</code_scheme>
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
# Code style for C++
|
||||||
|
|
||||||
|
**TODO**: Expand beyond naming and formatting
|
||||||
|
|
||||||
|
## Headers
|
||||||
|
|
||||||
|
* Headers should live in the same folder with it's implementation counterpart (if there's one)
|
||||||
|
* Headers should use header guards
|
||||||
|
|
||||||
|
## Naming
|
||||||
|
|
||||||
|
* Types should use `PascalCase`
|
||||||
|
* Local variables and function parameters should use `camelCase`
|
||||||
|
* Global variables should use `camelCase`
|
||||||
|
* Constants should use `kPascalCase` (with prefix `k`)
|
||||||
|
* Private functions (not visible outside a compilation unit) should use `camelCase`
|
||||||
|
* Exported functions (declared in headers or shared with Kotlin) should use `PascalCase`
|
||||||
|
* Member fields should use `camelCase`. Private member fields should add `_` suffix: `camelCase_`
|
||||||
|
* Member functions should use `camelCase`
|
||||||
|
* Macros should use `SCREAMING_SNAKE_CASE`
|
||||||
|
* namespaces should use `snake_case`
|
||||||
|
* `enum` and `enum class` members should use `kPascalCase`
|
||||||
|
|
||||||
|
If API is designed to mimic C++ stdlib (e.g. stubbing `<atomic>` for platforms that do not support it), its allowed
|
||||||
|
to follow stdlib naming conventions.
|
||||||
|
|
||||||
|
## Formatting
|
||||||
|
|
||||||
|
For automated formatting you can use [config for CLion](codestyle/cpp/CLionFormat.xml) or `clang-format` (see [config](.clang-format) at the repo's root). Note, that CLion uses `clang-format` by default; this can be turned off if you prefer to use rules from `CLionFormat.xml`.
|
||||||
|
|
||||||
|
Formatting rules are designed to closely mirror [Kotlin rules](https://kotlinlang.org/docs/reference/coding-conventions.html).
|
||||||
|
|
||||||
|
* Use spaces instead of tabs. Indentation width is 4 spaces. Continuation width is 8 spaces
|
||||||
|
* Do not indent namespaces
|
||||||
|
* Visibility modifiers are placed without indentation
|
||||||
|
* All operators should be wrapped with a space or a line break
|
||||||
|
* In pointer and reference definitions `*` and `&` should be placed on a type instead of a variable
|
||||||
|
* In pointer to functions prefer not to use `*` at all.
|
||||||
|
* Add a space between `template` and `<`
|
||||||
Reference in New Issue
Block a user