Skip to content

Use dprint for code formatting #228

@cb1kenobi

Description

@cb1kenobi

dprint is an awesome Rust-based tool that formats code, markdown, yaml, json, and more. It's faster than prettier and more importantly, exposes more knobs to control the formatting.

Since dprint doesn't support C++, it can call out to an external tool to do the formatting. In this case, we should be able to wire up clang-format.

Example dprint.json:

{
  "typescript": {
    "arguments.trailingCommas": "never",
    "lineWidth": 90,
    "parameters.trailingCommas": "never",
    "quoteStyle": "preferSingle",
    "trailingCommas": "onlyMultiLine",
    "useTabs": true
  },
  "json": {
  },
  "markdown": {
  },
  "toml": {
  },
  "malva": {
  },
  "markup": {
  },
  "yaml": {
    "quotes": "preferSingle"
  },
  "excludes": [
    "**/node_modules",
    "**/*-lock.json"
  ],
  "exec": {
    "commands": [
      {
        "command": "clang-format -i {{file_path}}",
        "exts": ["cpp", "cc", "cxx", "h", "hpp"]
      }
    ]
  },
  "plugins": [
    "https://plugins.dprint.dev/typescript-0.95.12.wasm",
    "https://plugins.dprint.dev/json-0.21.0.wasm",
    "https://plugins.dprint.dev/markdown-0.20.0.wasm",
    "https://plugins.dprint.dev/toml-0.7.0.wasm",
    "https://plugins.dprint.dev/g-plane/malva-v0.15.0.wasm",
    "https://plugins.dprint.dev/g-plane/markup_fmt-v0.24.0.wasm",
    "https://plugins.dprint.dev/g-plane/pretty_yaml-v0.5.1.wasm"
  ]
}

We may also need to specify the includes:

  "includes": ["**/*.{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