Skip to content

Commit 717e580

Browse files
authored
Merge pull request #11309 from Calinou/shaders-style-guide-auto-format
Document automatic formatting with clang-format in Shaders style guide
2 parents 4ff1c17 + 3406f57 commit 717e580

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

tutorials/shaders/shaders_style_guide.rst

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,44 @@ the console, extra indentation should **not** be added within ``#if``,
377377
#endif
378378
}
379379
380+
Applying formatting automatically
381+
---------------------------------
382+
383+
To automatically format shader files, you can use
384+
`clang-format <https://clang.llvm.org/docs/ClangFormat.html>`__ on one or several
385+
``.gdshader`` files, as the syntax is close enough to a C-style language.
386+
387+
However, the default style in clang-format doesn't follow this style guide,
388+
so you need to save this file as ``.clang-format`` in your project's root folder:
389+
390+
.. code-block:: yaml
391+
392+
BasedOnStyle: LLVM
393+
AlignAfterOpenBracket: DontAlign
394+
AlignOperands: DontAlign
395+
AlignTrailingComments:
396+
Kind: Never
397+
OverEmptyLines: 0
398+
AllowAllParametersOfDeclarationOnNextLine: false
399+
AllowShortFunctionsOnASingleLine: Inline
400+
BreakConstructorInitializers: AfterColon
401+
ColumnLimit: 0
402+
ContinuationIndentWidth: 8
403+
IndentCaseLabels: true
404+
IndentWidth: 4
405+
InsertBraces: true
406+
KeepEmptyLinesAtTheStartOfBlocks: false
407+
RemoveSemicolon: true
408+
SpacesInLineCommentPrefix:
409+
Minimum: 0 # We want a minimum of 1 for comments, but allow 0 for disabled code.
410+
Maximum: -1
411+
TabWidth: 4
412+
UseTab: Always
413+
414+
While in the project root, you can then call ``clang-format -i path/to/shader.gdshader``
415+
in a terminal to format a single shader file, or ``clang-format -i path/to/folder/*.gdshader``
416+
to format all shaders in a folder.
417+
380418
Code order
381419
----------
382420

0 commit comments

Comments
 (0)