clang-format config for Pawn

Started by SA:MP, May 05, 2023, 08:51 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

SA:MP

clang-format config for Pawn

I recently realised clang-format (the clang formatting tool for C++, Java, ObjC and a few other languages) quite happily reads most Pawn code.



You can check out the tool here: https://clang.llvm.org/docs/ClangFormat.html and play with configs here: https://clangformat.com/ or here: https://zed0.co.uk/clang-format-configurator/



So, being a lover of conventions and strict formatting, I attempted to write a clang format config for Pawn based on the conventions that the community have adopted over the years.



It looks like this:







And the configuration is:




Code:

---
BasedOnStyle: WebKit
IndentWidth: 4
---
Language: Cpp
AlignAfterOpenBracket: DontAlign
BreakBeforeBraces: Allman
BreakConstructorInitializers: BeforeColon
SpaceBeforeCtorInitializerColon: false
SpaceBeforeInheritanceColon: false
KeepEmptyLinesAtTheStartOfBlocks: false
MaxEmptyLinesToKeep: 1
SortIncludes: true
SpaceBeforeAssignmentOperators: false

The only issue, as you can see in the gif above, foreach is broken and I can't figure out a solution for it (outside of writing my own formatter - which was doing, and may continue).



If anyone wants to contribute, go ahead! It would be nice to have a universal format that is also enforced by a tool that can eventually be implemented into the Pawn Tools for VS Code extension so source code is formatted upon saving the file to save time while writing.

Source: clang-format config for Pawn