Skip to content

Commit 2a41226

Browse files
ayazhafizKeen Yee Liau
authored andcommitted
docs: add documentation about new clang-format formatter
Document how to use the `clang-format` formatter added to this repository in #372. Include instructions for formatting files on save in VS Code, IntelliJ IDEs, and Vim. Add a VS Code workspace setting configuration for enabling automatic source code formatting with the `clang-format` VS Code extension. Add `.vimrc` and `.nvimrc` so Vim and Neovim configurations of the formatter are local-only. Part of #373.
1 parent f5e041e commit 2a41226

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ integration/out
99
dist/
1010
**/.idea/
1111
**/tsconfig.tsbuildinfo
12+
.vimrc
13+
.nvimrc

.vscode/settings.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,11 @@
22
"editor.insertSpaces": true,
33
"tslint.enable": true,
44
"typescript.tsc.autoDetect": "off",
5-
"typescript.preferences.quoteStyle": "single"
5+
"typescript.preferences.quoteStyle": "single",
6+
"//format-on-save-comment": "Format ts files on save with `clang-format.executable`. If `clang-format.executable` is not being used, these two settings should be removed otherwise it will break existing formatting. You can instead run `yarn format` to manually format your code.",
7+
"[typescript]": {
8+
"editor.formatOnSave": true
9+
},
10+
"//clang-format-comment": "Please install https://marketplace.visualstudio.com/items?itemName=xaver.clang-format to take advantage of `clang-format` in VSCode. (See https://clang.llvm.org/docs/ClangFormat.html for more info `clang-format`.)",
11+
"clang-format.executable": "${workspaceRoot}/node_modules/.bin/clang-format"
612
}

DEVELOPER.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
## Formatting source code
2+
3+
This repository uses the [NPM distribution](https://www.npmjs.com/package/clang-format) of
4+
[`clang-format`](http://clang.llvm.org/docs/ClangFormat.html) to format source code.
5+
6+
Code is automatically formatted by running `yarn format`. You can also set up your IDE to format
7+
files on each save.
8+
9+
### VS Code
10+
11+
1. Install the
12+
[`Clang-Format` extension](https://marketplace.visualstudio.com/items?itemName=xaver.clang-format)
13+
for VS Code.
14+
15+
VS Code will automatically pick up relevant settings from this repository's
16+
[`.vscode/settings.json`](./.vscode/settings.json).
17+
18+
### WebStorm / IntelliJ
19+
20+
1. Install the [`ClangFormatIJ`](https://plugins.jetbrains.com/plugin/8396-clangformatij) plugin for
21+
IntelliJ IDEs.
22+
2. Open `Preferences->Tools->clang-format`.
23+
3. Set the field named "PATH" to `<PATH_TO_REPOSITORY>/node_modules/.bin/`.
24+
25+
### Vim
26+
27+
1. Install [Vim Clang-Format](https://github.com/rhysd/vim-clang-format).
28+
2. Create a [project-specific `.vimrc`](https://andrew.stwrt.ca/posts/project-specific-vimrc/) in
29+
the repository root directory containing
30+
31+
```vim
32+
let g:clang_format#command = '<PATH_TO_REPOSITORY>/node_modules/.bin/clang-format'
33+
```

0 commit comments

Comments
 (0)