- Download and store the
clang-format.exe
in a specific directory. - Copy
.clang-format
to the project directory. - Install extension
Clang-Format
in vscode and edit the config setting. 3.1 Runnpm install clang-format -g
to install clang-format in all platforms. the clang-path would be '${workspaceRoot}/node_modules/.bin/clang-format', in linux is:/usr/local/lib/node_modules/clang-format/bin/linux_x64/clang-format
{
"clang-format.language.javascript.enable": false,
"clang-format.executable": "C:\\clang-format.exe",
}
- Use key
Alt+shift+f
to format the whole c/cpp file and usectrl k + ctrl f
to format the selected code block. - The format setting is detailed in
.clang-format
, which follows google's programing style and could be checked usingcpplint.py
. - A few rules are modified to make the format style more readable, and if you donn't want to format specific code, add the comment in your code.
// clang-format off
void unformatted_code ;
// clang-format on
void formatted_code_again;
If some format result didn't pass the check of cpplint.py, adjust it yourself and add the comment above.
more details:
https://clang.llvm.org/docs/ClangFormatStyleOptions.html
https://www.cnblogs.com/PaulpauL/p/5929753.html
Here eslint is used in vscode by install extension ESLint
and install the node module.
npm install eslint babel-eslint eslint-plugin-html -g
install globally may not work, better install every root dir of your project.
the config setting will be:
{
"eslint.options": {
"configFile": "C:/.eslintrc.js"
},
"editor.detectIndentation": false
}
ESLint is just a hint where you did not follow the style guide.
Format the js code could still use the key in vscode: Alt+shift+f
or ctrl k + ctrl f
.
EACCESS problem: ref
sudo chown -R $(whoami) /usr/local/lib/node_modules