ClangFormat Beautifier
About
ClangFormat beautifier for Unibeautify
Package | Docs | Latest |
---|---|---|
@unibeautify/beautifier-clang-format | v0.2.0 | |
unibeautify | v0.17.1 |
Prerequisites
Please install the following prerequisites.
ClangFormat executable
ClangFormat executable should not be confused with ClangFormat beautifier with the same name. Executables are non-Node.js tools for code formatting while beautifiers are Node.js packages which wrap an executable to be used by Unibeautify.
ClangFormat executable is a third-party program you must install manually and is required for beautification.
See https://clang.llvm.org/docs/ClangFormat.html for more information.
Install ClangFormat (clang-format
) by following https://clang.llvm.org/docs/ClangFormat.html.
If you have questions or want to report a bug, go to https://clang.llvm.org/docs/ClangFormat.html.
Install
Install with npm
:
npm install --save-dev unibeautify @unibeautify/beautifier-clang-format
Or with yarn
:
yarn add --dev unibeautify @unibeautify/beautifier-clang-format
Usage
Add ClangFormat
to beautifiers
language option.
A .unibeautifyrc.json
file would look like the following:
{
"LANGUAGE_NAME": {
"beautifiers": [
"ClangFormat"
]
}
}
Note: The
LANGUAGE_NAME
should be replaced with your desired supported language name, such asC
,C++
,Java
, etc.
Advanced
The following beautifier option(s) are supported:
prefer_beautifier_config
See beautifier options docs for more information.
Example advanced configuration:
{
"LANGUAGE_NAME": {
"beautifiers": [
"ClangFormat"
],
"ClangFormat": {
"prefer_beautifier_config": true,
"ClangFormat": {
"path": "/absolute/path/to/clang-format"
}
}
}
}
Options
No configuration options are supported. The following languages are supported without options: C, C++, Java, Objective-C.
FAQ
How to use ClangFormat in Atom, VSCode, and other editors?
See the editor integration documentation for installation instructions for your editor of choice.
How to use ClangFormat configuration file?
You can override Unibeautify configuration and use ClangFormat's own configuration file instead with prefer_beautifier_config
beautifier option.
{
"LANGUAGE_NAME": {
"beautifiers": [
"ClangFormat"
],
"ClangFormat": {
"prefer_beautifier_config": "path/to/ClangFormat/config/file"
}
}
}
See beautifier options docs for more information.
How to enable ClangFormat to format on save?
See the editor integration documentation for format on save instructions for your editor of choice.
How to run ClangFormat on all files?
You can run ClangFormat on all of your files for every commit with Unibeautify CI.
Is there a ClangFormat sandbox or playground?
You can quickly try ClangFormat online with Unibeautify Playground.
Troubleshooting
Below are instructions for each of the supported Operating Systems.
Windows
Open the Command Prompt.
Show me how to open the Command Prompt.
Find the path to ClangFormat by running the command:
where clang-format
Which will return an absolute path like one of the following:
C:\absolute\path\to\clang-format
C:\absolute\path\to\clang-format.exe
C:\absolute\path\to\clang-format.bat
If where
fails to return an executable path then you need to fix your PATH
Environment Variable.
Show me how to change my
PATH
environment variable.
If you know the executable path go to the Configure section and replace /absolute/path/to/clang-format
with your specific executable path value.
macOS
Open the Terminal application.
Show me how to open the Terminal.
Find the path to ClangFormat by running the command:
which clang-format
Which will return an absolute path like one of the following:
/absolute/path/to/clang-format
/absolute/path/to/clang-format.sh
/absolute/path/to/clang-format.bash
If which
fails to return an executable path then you need to fix your PATH
Environment Variable:
Show me how to change my
PATH
environment variable.
If you know the executable path go to the Configure section and replace /absolute/path/to/clang-format
with your specific executable path value.
Linux
Open the Terminal application.
Show me how to open the Terminal.
Find the path to ClangFormat by running the command:
which clang-format
Which will return an absolute path like one of the following:
/absolute/path/to/clang-format
/absolute/path/to/clang-format.sh
/absolute/path/to/clang-format.bash
If which
fails to return an executable path then you need to fix your PATH
Environment Variable.
Show me how to change my
PATH
environment variable.
If you know the executable path go to the Configure section replace /absolute/path/to/clang-format
with your specific executable path value.