Skip to content

Use clang-format for C++ formatting #317

@cb1kenobi

Description

@cb1kenobi

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:

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"]
      }
    ]
  },

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions