├── before_after_clang_format.gif ├── LICENSE ├── .clang-format └── README.md /before_after_clang_format.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TensorWorks/UE-Clang-Format/HEAD/before_after_clang_format.gif -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 TensorWorks 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /.clang-format: -------------------------------------------------------------------------------- 1 | StatementMacros: ['UPROPERTY', 'UFUNCTION', 'UCLASS', 'USTRUCT', 'UENUM', 'UINTERFACE', 'GENERATED_BODY'] 2 | Language: Cpp 3 | BasedOnStyle: LLVM 4 | 5 | AccessModifierOffset: -4 6 | AlignAfterOpenBracket: DontAlign 7 | AlignConsecutiveDeclarations: true 8 | AlignEscapedNewlines: Left 9 | AlignOperands: DontAlign 10 | AlignTrailingComments: true 11 | AllowShortBlocksOnASingleLine: Empty 12 | AllowShortEnumsOnASingleLine: false 13 | AllowShortFunctionsOnASingleLine: Inline 14 | AllowShortLambdasOnASingleLine: All 15 | BraceWrapping: 16 | AfterCaseLabel: true 17 | AfterClass: true 18 | AfterControlStatement: true 19 | AfterEnum: true 20 | AfterFunction: true 21 | AfterNamespace: true 22 | AfterObjCDeclaration: true 23 | AfterStruct: true 24 | AfterUnion: true 25 | AfterExternBlock: true 26 | BeforeCatch: true 27 | BeforeElse: true 28 | BeforeLambdaBody: false 29 | BeforeWhile: true 30 | IndentBraces: false 31 | BreakBeforeBinaryOperators: NonAssignment 32 | BreakBeforeBraces: Custom 33 | BreakInheritanceList: AfterColon 34 | BreakBeforeTernaryOperators: true 35 | BreakConstructorInitializers: BeforeComma 36 | BreakStringLiterals: false 37 | ColumnLimit: 0 38 | ConstructorInitializerAllOnOneLineOrOnePerLine: true 39 | Cpp11BracedListStyle: false 40 | EmptyLineBeforeAccessModifier: LogicalBlock 41 | IndentCaseBlocks: false 42 | IndentCaseLabels: true 43 | IndentPPDirectives: BeforeHash 44 | IndentWidth: 4 45 | NamespaceIndentation: All 46 | PointerAlignment: Left 47 | SortIncludes: false 48 | SpaceBeforeCaseColon: false 49 | TabWidth: 4 50 | UseTab: Always 51 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![Before and After](./before_after_clang_format.gif) 2 | 3 | # Clang Format for Unreal Engine C++ 4 | Automatically format your Unreal Engine C++ as per [Epic's Coding Standard](https://docs.unrealengine.com/4.27/en-US/ProductionPipelines/DevelopmentSetup/CodingStandard/). 5 | 6 | The purpose of this repository is to provide a Clang-Format configuration for Unreal Engine C++ and instructions for how to use it. 7 | 8 | ## Get the .clang-format file 9 | [.clang-format file](./.clang-format) 10 | 11 | ## VS Code 12 | 1. Put the `.clang-format` file in the root of your project (or the engine root if you are working on the engine itself). 13 | 2. As long as you have [Microsoft's C++ extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools) installed in VSCode you can now format with `Shift+Alt+F`. (If not, [read here](https://code.visualstudio.com/docs/cpp/cpp-ide#_code-formatting)). 14 | 15 | **Optional:** You can enable `format on save` for C++ by adding the following to your `*.code-workspace` file: 16 | ``` 17 | "settings": { 18 | "[c++]": { 19 | "editor.formatOnSave": true 20 | } 21 | }, 22 | ``` 23 | 24 | ## Visual Studio 25 | 1. Go to the root of you project, `File->Add New Item->ClangFormat File`. 26 | 2. Copy+Paste the contents of the .clang-format from this repository into the newly generated `.clang-format` file. 27 | 3. You can now format files with `Ctrl+K+D` 28 | 29 | **Optional:** You can enable `format on save` by installing [this extension](https://marketplace.visualstudio.com/items?itemName=mynkow.FormatdocumentonSave). 30 | 31 | ## Limitations 32 | 1. Method chaining is not supported by clang-format and offers inconsistent results, especially inside of square brackets (`[`, `]`) such as used extensively by Slate. 33 | 2. Single-line lambdas are incompatible with Allman-style brace wrapping and cannot be supported with the currently available ruleset. 34 | --------------------------------------------------------------------------------