X Tutup
Skip to content

Commit 271ced8

Browse files
alexeaglemhevery
authored andcommitted
Update DEVELOPER.md
add some info about clang-format
1 parent c5bd3f0 commit 271ced8

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

DEVELOPER.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ JS and Dart versions. It also explains the basic mechanics of using `git`, `node
88
* [Environment Variable Setup](#environment-variable-setup)
99
* [Installing NPM Modules and Dart Packages](#installing-npm-modules-and-dart-packages)
1010
* [Running Tests Locally](#running-tests-locally)
11+
* [Formatting](#formatting)
1112
* [Project Information](#project-information)
1213
* [CI using Travis](#ci-using-travis)
1314
* [Transforming Dart code](#transforming-dart-code)
@@ -194,6 +195,36 @@ Angular specific command line options when running protractor:
194195
Angular specific command line options when running protractor (e.g. force gc, ...):
195196
`$(npm bin)/protractor protractor-{js|dart2js}-conf.js --ng-help`
196197

198+
## Formatting
199+
200+
We use [clang-format](http://clang.llvm.org/docs/ClangFormat.html) to automatically enforce code style for our TypeScript code. This allows us to focus our code reviews more on the content, and less on style nit-picking. It also lets us encode our style guide in the `.clang-format` file in the repository, allowing many tools and editors to share our settings.
201+
202+
To check the formatting of your code, run
203+
204+
gulp check-format
205+
206+
Note that the continuous build on Travis runs `gulp enforce-format`. Unlike the `check-format` task, this will actually fail the build if files aren't formatted according to the style guide.
207+
208+
Your life will be easier if you include the formatter in your standard workflow. Otherwise, you'll likely forget to check the formatting, and waste time waiting for a build on Travis that fails due to some whitespace difference.
209+
210+
* **git pre-commit hook** is available at [llvm.org](https://llvm.org/svn/llvm-project/cfe/trunk/tools/clang-format/git-clang-format). This will automatically format your delta regions when you commit a change. To install, first patch this file to add `.ts` to the `default_extensions` section. Then copy the file somewhere in your path, for example, `/usr/local/git/current/bin/git-clang-format`. Make sure it is executable. Then, in the angular repo, run
211+
212+
$ echo -e '#!/bin/sh\nexec git clang-format' > .git/hooks/pre-commit
213+
$ chmod u+x !$
214+
215+
* **WebStorm** can run clang-format on the current file.
216+
1. Under Preferences, open Tools > External Tools.
217+
1. Plus icon to Create Tool
218+
1. Fill in the form:
219+
- Name: clang-format
220+
- Description: Format
221+
- Synchronize files after execution: checked
222+
- Open console: not checked
223+
- Show in: Editor menu
224+
- Program: [path to clang-format, try `$ echo $(npm config get prefix)/bin/clang-format`]
225+
- Parameters: `-i -style=file $FilePath$`
226+
- Working directory: `$ProjectFileDir$`
227+
197228
## Project Information
198229

199230
### Folder structure

0 commit comments

Comments
 (0)
X Tutup