From 3406f57f23d39bd9bd72ca930974634766352201 Mon Sep 17 00:00:00 2001 From: Hugo Locurcio Date: Fri, 19 Sep 2025 17:00:32 +0200 Subject: [PATCH] Document automatic formatting with clang-format in Shaders style guide --- tutorials/shaders/shaders_style_guide.rst | 38 +++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/tutorials/shaders/shaders_style_guide.rst b/tutorials/shaders/shaders_style_guide.rst index 108954d76..001292b09 100644 --- a/tutorials/shaders/shaders_style_guide.rst +++ b/tutorials/shaders/shaders_style_guide.rst @@ -377,6 +377,44 @@ the console, extra indentation should **not** be added within ``#if``, #endif } +Applying formatting automatically +--------------------------------- + +To automatically format shader files, you can use +`clang-format `__ on one or several +``.gdshader`` files, as the syntax is close enough to a C-style language. + +However, the default style in clang-format doesn't follow this style guide, +so you need to save this file as ``.clang-format`` in your project's root folder: + +.. code-block:: yaml + + BasedOnStyle: LLVM + AlignAfterOpenBracket: DontAlign + AlignOperands: DontAlign + AlignTrailingComments: + Kind: Never + OverEmptyLines: 0 + AllowAllParametersOfDeclarationOnNextLine: false + AllowShortFunctionsOnASingleLine: Inline + BreakConstructorInitializers: AfterColon + ColumnLimit: 0 + ContinuationIndentWidth: 8 + IndentCaseLabels: true + IndentWidth: 4 + InsertBraces: true + KeepEmptyLinesAtTheStartOfBlocks: false + RemoveSemicolon: true + SpacesInLineCommentPrefix: + Minimum: 0 # We want a minimum of 1 for comments, but allow 0 for disabled code. + Maximum: -1 + TabWidth: 4 + UseTab: Always + +While in the project root, you can then call ``clang-format -i path/to/shader.gdshader`` +in a terminal to format a single shader file, or ``clang-format -i path/to/folder/*.gdshader`` +to format all shaders in a folder. + Code order ----------