> For the complete documentation index, see [llms.txt](https://lifeexe-art.gitbook.io/unreal-engine-c-course-eng/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lifeexe-art.gitbook.io/unreal-engine-c-course-eng/automation/code-formatting.md).

# Code formatting

## .clang-format

For automatic formatting of project files, the file **format\_all\_files.bat** is located in the root of the repositories.

&#x20;It essentially calls **.clang-format** on all project files:

```bash
@echo off
CD Source
FOR /R %%f IN (*.cpp, *.h, *.cs) DO (
    clang-format -i %%f
    echo %%f
)

```

In order for the script to work correctly, you need to add the path to **clang-format** to your **PATH** environment variable. The program is located in the **Visual Studio** directory. 99% that you have the same path:

`c:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\Llvm\bin\`

## How to set an environment variable

In the Windows search, enter **environment** and open **System Properties:**

![](https://3452651321-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MaORk4ZJi6SeCOun3D0%2F-Mb0G8exDFQlX-dfzj0u%2F-Mb0GTgct4lGWO2Qs74G%2F1.png?alt=media\&token=11102cbc-e2f4-4884-a9ab-65000f9223b3)

Click on **Environment Variables:**

![](https://3452651321-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MaORk4ZJi6SeCOun3D0%2F-Mb0G8exDFQlX-dfzj0u%2F-Mb0GginMNOJSncA_v2X%2F2.png?alt=media\&token=110eb9d7-c88d-4a6f-96c7-f48406f757e4)

Select **Path** and click on **Edit:**

![](https://3452651321-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MaORk4ZJi6SeCOun3D0%2F-Mb0G8exDFQlX-dfzj0u%2F-Mb0GnccewKKGuG2N4YO%2F3.png?alt=media\&token=186815cd-91aa-407f-b60d-26bf7c88282c)

Insert the path to **clang-format** into the list, click on **OK:**

![](https://3452651321-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MaORk4ZJi6SeCOun3D0%2F-Mb0G8exDFQlX-dfzj0u%2F-Mb0Gw5ZDwerSYXY1ypa%2F4.png?alt=media\&token=d881db01-b181-4f20-aae4-93ec6e757a77)

You can check that everything is ok on the command line using one of the commands:

```bash
clang-format -version

where clang-format
```

The output should be as follows:

![](https://3452651321-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MaORk4ZJi6SeCOun3D0%2F-Mb0G8exDFQlX-dfzj0u%2F-Mb0H6R6G3TN6Rn0z0Bt%2F5.png?alt=media\&token=002d4b35-633a-4b9e-bf74-dae18ff0b341)

After that, you can use the script **format\_all\_files.bat**

## Code Formatting Plugins for Visual Studio

* [VS plugin to format all files](https://marketplace.visualstudio.com/items?itemName=munyabe.FormatAllFiles)
* [VS plugin for formatting when saving a file](https://marketplace.visualstudio.com/items?itemName=mynkow.FormatdocumentonSave)
