HarperFast / HarperFast/rocksdb-js

Use `clang-format` for C++ formatting

Open
#317 0 comments 0 reactions 1 assignee Claimed by @cb1kenobi View on GitHub
enhancement
Dominant language
C++
Stars
21
Forks
2
Avg merge
2d 9h
Merged PRs (30d)
36

Description

Code is formatted using `dprint`, however `dprint` does not support C++. Instead it can call out to external processes to do the formatting. In this case, it seems the tool of choice is `clang-format`.

NOTE: This issue should be completed using upcoming Clang 22 release. The current Clang 21 does not do a good job formatting C++ features such as lambdas. Clang 22 is slated to be release Feb 24, 2026.

There are two maintained npm packages that distribute `clang-format`:
- https://www.npmjs.com/package/clang-format-node
- https://www.npmjs.com/package/@wasm-fmt/clang-format

The former bundles the compiled binaries for each platform. The later compiles `clang-format` and distributes as wasm. Both offer very similar performance. It's a matter of picking a horse.

In `dprint.json`, enable the `exec` configuration:

```
"exec": {
"cwd": "${configDir}",
"commands": [
{
"command": "pnpm clang-format-node -- -i {{file_path}}",
"exts": ["cpp", "cc", "cxx", "h", "hpp"]
}
]
},
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.