Interactively create a clang-format configuration while watching how the changes affect your code.
Check it out at https://clang-format-configurator.site/
Clang-format-configurator-v2 is a written from scratch successor of clang-format-configurator with following bugs fixed and new features implemented:
Clang-format tool defaults all unset options to values from selected BasedOnStyle when doing formatting, this configurator follows such behaviour: every time BasedOnStyle
is changed, all options are filled with values from selected style, when user uploads their .clang-format config file, configurator also automatically fills all unset options to match style from user's config.
Default values for enum options in dropdown selectors are marked with asterisk (*) on Firefox and with different color and italic font style on other browsers. Default values for strings and numbers are set as a placeholder (can be seen when input field is empty). Setting dropdown selectors to blank does the same thing as setting them to current style's default value.
String selectors have "Unset" button to the right of an edit field and work this way:
Active option with empty string in it is set to an empty string
Array selectors have big red X buttons and big blue + buttons. First ones delete element above them, second ones append new empty element to the end. There are no empty arrays, because clang-format treats them the same way as unset option.
"Autoformat on changes" checkbox is quite self explanatory, works both for code changes and option changes
Deprecated options are placed at the bottom of the list and have strikethrough title style
Red "overridden by X" warning means that this option value is overridden by X option value. Currently, works only for BraceWrapping
and BreakBeforeBraces
. If you know other options that override something, please let me know by creating an Issue.
Legacy values (None, Consecutive, AcrossEmptyLines, AcrossComments, AcrossEmptyLinesAndComments
) for AlignConsecutive*
are not supported by configurator.
Well, "Upload"/"Download" buttons are for uploading/downloading config file, editor is for editing or copypasting config file contents in-place. "Close" button disgards all changes to config file, "Load Config" buttons applies them.
"Remove duplicates with BasedOnStyle (Not tested)" checkbox is for removing options, which values match selected BasedOnStyle style. This feature is not properly tested.
Configurator formats code on the left/top panel, code on the right/bottom panel is left unchanged.
Btw, if you want to make formatting as close as possible to existing formatted code, then try clang-unformat
Requirements: docker, nodejs, linux or wsl
Build clang-format binaries and frontend config
llvm/prepare.sh
script creates debian docker image, builds clang-format from source, dumps styles and copy artifacts outside of container, then launches llvm/build-config.py
script
Whole process takes around 30 minutes on Intel i5 12600
cd llvm
./prepare.sh --all
Clang-format binaries are placed in server/third-party/clang-format
direcotry, docs and defaults are in llvm/docs/
and llvm/defaults/
respectively and config is written into llvm/config.json
. front-end/src/config.json
is a soft link to llvm/config.json
Install JS dependencies
cd front-end
npm install
Configure server and client
front-end/src/config.json
using FormatApiUrl
key, or keep http://localhost:8080/format?
by defaultserver/config.json
using key bind-addr
server/config.json
using keys certificate-file
and key-file
or leave it empty to run plain HTTP server without encryptionRun and Debug with VS Code
List of clang-format versions is written in TAGS variable in llvm/prepare.sh
script. This array holds git tag names, tag format must follow this pattern: "llvmorg-x.x.x", because get-version-from-tag
extracts version string from tag name. If you want to support a version, which tag name does not follow this pattern, then modify get-version-from-tag
function. Unless it works as is, idk
Run llvm/prepare.sh
to build new version binaries and build frontend config file.
Then, manually modify "versions" array in backend config file server/config.json
.
Config file format is not documented. It's generated by llvm/build-config.py
script, and this script is utter shitcode. Even I don't understand how it works anymore.