We utilize (a slightly modified version of) the Linux Kernel Clang Formatter, which enforces Linux style syntax.
Within all C repositories, a GitHub Action is setup to check that all files have been formatted accordingly, and pull requests will not be able to merge unless it passes this check.
Fortunately, this formatter can be run by the user to automatically update their code to abide by these standards.
This process only works for NER applications, not for Embedded Base itself. If/when we get this running for embedded base, the process for running it on a file within that directory will be included below
This purposely will ignore and not format auto generated files like main.c and all HAL files. This is okay and intentional
To setup and run the clang format:
In VScode:
Open VScode from any NER C project
Open file-->preferences-->settings
Type clang in the settings search bar
Change
C_Cpp: Clang_format_fallback Style
tonone
Change
C_Cpp: Clang_format_style
tofile:${workspaceRoot}/Drivers/Embedded-Base/clang-format
Change
editor.formatOnSave
totrue
Note that with these settings, the linter will run automatically every time you save a file in VScode. If you prefer this not to happen, you can opt out of this by ignoring step 6 above. In doing so, the linter will not run on save, and will have to be done with Ctr + i.
In CLI:
Debian based Linux:
sudo apt-get install clang-format clang-format -style=file -i path/to/your/file.c -assume-filename=path/to/your/.clang-format
Windows:
IDK tbh why are you using CLI if you are on windows anyway
(probably have to manually install clang for windows then update your path or something, y’all can figure it out, I think once it is installed correctly the command is the same as Linux and Mac)
Mac:
brew install clang-format clang-format -style=file -i path/to/your/file.c -assume-filename=path/to/your/.clang-format
(obviously use whatever package manager you want for Linux and Mac)
Clang Ignore
If ever there is a block of code that needs an exception to this formatter, which does happen on occasion, you can encapsulate that code within these comments:
// clang-format off ... // clang-format on