@cpp-linter/clang-format

中文文档
23.1.5发布于 2026/11/08MITTypeScriptCommonJS零依赖构建来源已验证近 30 天下载 3569

clang-format, the C/C++ code formatter from LLVM, as a static binary (LLVM 23.1.5).

原始使用文档
文档目录3 节
  1. How it is installed
  2. From Node.js
  3. Where the binaries come from

@cpp-linter/clang-format

part of cpp-linter

clang-format 23.1.5 as a static binary, for Linux, macOS and Windows on x64 and arm64.

npm install --save-dev @cpp-linter/clang-format@23
npx clang-format -i src/*.cpp
# check only, for CI
npx clang-format --dry-run --Werror src/*.cpp

The npm version is the LLVM version. clang-format output changes between LLVM major versions, so pin one: @cpp-linter/clang-format@23 always installs the newest LLVM 23 release. Older LLVM majors are under the Versions tab, such as @cpp-linter/clang-format@18.

How it is installed

This package has one optional dependency per platform, such as @cpp-linter/clang-format-linux-x64, and npm installs only the one for your machine. Nothing is downloaded or run at install time, so it works with --ignore-scripts, pnpm, Yarn, offline caches and private registry mirrors.

From Node.js

const clangFormat = require('@cpp-linter/clang-format');

clangFormat.binaryPath(); // absolute path of the clang-format binary
clangFormat.run(['--version']); // runs it and returns the exit code

Where the binaries come from

They are built from the LLVM source by cpp-linter/clang-tools-static-binaries, with a GitHub build attestation for every file. Before publishing, the release workflow checks each binary's sha512 and attestation, and the packages are published from GitHub Actions with npm provenance.

Website · Source · Issues · Discussions

版本与发布记录

@cpp-linter/clang-format 共发布 23 个版本,首次发布于 2026/10/23;过去 12 个月发布了 23 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
23.1.5latest2026/11/083 天前
14.0.62026/11/029 天前
13.0.12026/11/029 天前
18.1.82026/11/029 天前
15.0.72026/11/029 天前
16.0.62026/11/029 天前

其他发布通道:llvm-22 → 22.1.8,llvm-17 → 17.0.6,llvm-12 → 12.0.1,llvm-21 → 21.1.8,llvm-20 → 20.1.8,llvm-19 → 19.1.7。

关于 @cpp-linter/clang-format 的常见问题

@cpp-linter/clang-format 是什么?

clang-format, the C/C++ code formatter from LLVM, as a static binary (LLVM 23.1.5).

如何安装 @cpp-linter/clang-format?

在项目目录运行 npm install @cpp-linter/clang-format,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 clang-format,可以用 npx clang-format 直接运行。

@cpp-linter/clang-format 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@cpp-linter/clang-format 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@cpp-linter/clang-format 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=18。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@cpp-linter/clang-format 可以商用吗?

@cpp-linter/clang-format 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@cpp-linter/clang-format 的下载量有多少?

根据 npm 官方下载统计,@cpp-linter/clang-format 在 2026/10/11 – 2026/11/09 这 30 天内被下载 3,569 次,日均约 119 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@cpp-linter/clang-format 还在维护吗?

最新版本 23.1.5 发布于 2026/11/08(3 天前);至今共发布 23 个版本,其中过去 12 个月发布了 23 个;首次发布于 2026/10/23。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。