clang-format-node is a Node.js wrapper that provides programmatic access to the LLVM project's `clang-format` and `git-clang-format` native binaries. The current stable version is 3.0.2, bundling LLVM clang-format version 22.1.3. This package securely builds and bundles these native binaries directly from official LLVM source code, eliminating third-party binary dependencies and offering full GitHub Actions Attestation and npm Build Provenances for enhanced supply chain security. It also includes separate packages within its monorepo, `clang-format-git` for standalone Git integration without Python, and `clang-format-git-python` for the original Python script wrapper. Release cycles typically align with new LLVM clang-format versions, ensuring access to the latest formatting capabilities and bug fixes. It is inspired by `angular/clang-format` but aims for a more streamlined and secure integration into Node.js and npm workflows.
npm install clang-format-nodeVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to import and use the asynchronous `format` function to apply `clang-format` styling to a C++ code string using different style presets. It includes error handling for formatting failures.
Review your `.clang-format` configuration files against the new LLVM version's capabilities, as formatting rules may have evolved. Test formatting output thoroughly before upgrading in production. Ensure your Node.js environment meets the `>=16` requirement.
Verify that your operating system and architecture are explicitly listed as supported in the package's documentation. In case of binary execution issues, ensure the Node.js process has proper execution permissions and that no security software is interfering. Consider using a supported Docker image for consistent environments in CI.
For general code formatting, install `clang-format-node`. If you need `git-clang-format` functionality and want to avoid a Python dependency, install `clang-format-git`. If you prefer the original Python-dependent `git-clang-format` wrapper, install `clang-format-git-python`.
Upgrade your Node.js environment to version 16 or higher. Tools like `nvm` (Node Version Manager) can help manage different Node.js versions on your system.
Ensure your OS and CPU architecture are supported by `clang-format-node`. Check the integrity of your `node_modules` and try reinstalling the package. If in a container or CI, verify permissions for binary execution. Consult the official documentation's 'Supported' section for compatible environments.
Configure your project to use ES Modules (e.g., by adding `"type": "module"` to your `package.json`) or use a transpiler (like TypeScript or Babel) to convert ESM syntax to CommonJS if you must target a CJS environment.
Always pass a string representing the code to be formatted as the first argument to the `format` function. Implement input validation before calling the formatter.
No dependency data recorded yet.