Skip to content

Commit d1f7900

Browse files
committed
docs: consolidate clang-format docs.
Move the section from `CONTRIBUTING.md` (which should only be policy) to `DEVELOPER.md` (which should document developer tooling). Consolidates the whole thing a bit, and adjusts for the now always installed `git clang-format` hook. Also mentions clang-format's lookup behaviour.
1 parent 393f703 commit d1f7900

File tree

2 files changed

+34
-39
lines changed

2 files changed

+34
-39
lines changed

CONTRIBUTING.md

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ If you find a bug in the source code or a mistake in the documentation, you can
2828
## <a name="feature"></a> Want a Feature?
2929
You can *request* a new feature by [submitting an issue](#submit-issue) to our [GitHub
3030
Repository][github]. If you would like to *implement* a new feature, please submit an issue with
31-
a proposal for your work first, to be sure that we can use it. Angular 2 is in developer preview
32-
and we are not ready to accept major contributions ahead of the full release.
31+
a proposal for your work first, to be sure that we can use it. Angular 2 is in developer preview
32+
and we are not ready to accept major contributions ahead of the full release.
3333
Please consider what kind of change it is:
3434

3535
* For a **Major Feature**, first open an issue and outline your proposal so that it can be
@@ -135,22 +135,9 @@ To ensure consistency throughout the source code, keep these rules in mind as yo
135135
136136
* All features or bug fixes **must be tested** by one or more specs (unit-tests).
137137
* All public API methods **must be documented**. (Details TBC).
138-
* With the exceptions listed below, we follow the rules contained in
139-
[Google's JavaScript Style Guide][js-style-guide]:
140-
* Wrap all code at **100 characters**.
141-
142-
### <a name="clang-format">clang-format</a>
143-
The Angular project uses [`clang-format`](http://clang.llvm.org/docs/ClangFormat.html) to
144-
automatically format its source and enforce the common coding style. A couple of tips:
145-
146-
* Install clang-format with `npm install -g clang-format`.
147-
* Use `clang-format -i [file name]` to format a file (or multiple).
148-
* Use `gulp enforce-format` to check if your code is `clang-format` clean. This also gives
149-
you a command line to format your code.
150-
* `clang-format` also includes a git hook, run `git clang-format` to format all files you
151-
touched.
152-
* `clang-format` integrations are available for many popular editors (`vim`, `emacs`,
153-
`Sublime Text`, etc.)
138+
* We follow [Google's JavaScript Style Guide][js-style-guide], but wrap all code at
139+
**100 characters**. An automated formatter is available, see
140+
[DEVELOPER.md](DEVELOPER.md#clang-format).
154141

155142
## <a name="commit"></a> Commit Message Guidelines
156143

@@ -188,7 +175,7 @@ Must be one of the following:
188175
generation
189176

190177
### Scope
191-
The scope could be anything specifying place of the commit change. For example
178+
The scope could be anything specifying place of the commit change. For example
192179
`Compiler`, `ElementInjector`, etc.
193180

194181
### Subject

DEVELOPER.md

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ Karma is run against the new output.
175175
much easier to debug. `xit` and `xdescribe` can also be useful to exclude a test and a group of
176176
tests respectively.
177177

178-
### E2e tests
178+
### E2E tests
179179

180180
1. `$(npm bin)/gulp build.js.cjs` (builds benchpress and tests into `dist/js/cjs` folder).
181181
2. `$(npm bin)/gulp serve.js.prod serve.js.dart2js` (runs a local webserver).
@@ -195,30 +195,36 @@ Angular specific command line options when running protractor:
195195
Angular specific command line options when running protractor (e.g. force gc, ...):
196196
`$(npm bin)/protractor protractor-{js|dart2js}-conf.js --ng-help`
197197

198-
## Formatting
198+
## Formatting with <a name="clang-format">clang-format</a>
199199

200-
We use [clang-format](http://clang.llvm.org/docs/ClangFormat.html) to automatically enforce code style for our TypeScript code.
201-
This allows us to focus our code reviews more on the content, and less on style nit-picking.
202-
It also lets us encode our style guide in the `.clang-format` file in the repository,
203-
allowing many tools and editors to share our settings.
200+
We use [clang-format](http://clang.llvm.org/docs/ClangFormat.html) to automatically enforce code
201+
style for our TypeScript code. This allows us to focus our code reviews more on the content, and
202+
less on style nit-picking. It also lets us encode our style guide in the `.clang-format` file in the
203+
repository, allowing many tools and editors to share our settings.
204204

205205
To check the formatting of your code, run
206206

207207
gulp check-format
208208

209-
Note that the continuous build on Travis runs `gulp enforce-format`.
210-
Unlike the `check-format` task, this will actually fail the build if files aren't formatted according to the style guide.
211-
212-
Your life will be easier if you include the formatter in your standard workflow.
213-
Otherwise, you'll likely forget to check the formatting,
214-
and waste time waiting for a build on Travis that fails due to some whitespace difference.
215-
216-
* **git pre-commit hook** is available at
217-
[llvm.org](https://llvm.org/svn/llvm-project/cfe/trunk/tools/clang-format/git-clang-format).
218-
This will automatically format your delta regions when you commit a change.
219-
To install, first patch this file to add `.ts` to the `default_extensions` section.
220-
Then copy the file somewhere in your path, for example, `/usr/local/git/current/bin/git-clang-format`.
221-
Make sure it is executable. Then, in the angular repo, run
209+
Note that the continuous build on Travis runs `gulp enforce-format`. Unlike the `check-format` task,
210+
this will actually fail the build if files aren't formatted according to the style guide.
211+
212+
Your life will be easier if you include the formatter in your standard workflow. Otherwise, you'll
213+
likely forget to check the formatting, and waste time waiting for a build on Travis that fails due
214+
to some whitespace difference.
215+
216+
* Install clang-format with `npm install -g clang-format`.
217+
* Use `clang-format -i [file name]` to format a file (or multiple).
218+
Note that `clang-format` tries to load a `clang-format` node module close to the sources being
219+
formatted, or from the `$CWD`, and only then uses the globally installed one - so the version used
220+
should automatically match the one required by the project.
221+
Use `clang-format -version` in case you get confused.
222+
* Use `gulp enforce-format` to check if your code is `clang-format` clean. This also gives
223+
you a command line to format your code.
224+
* `clang-format` also includes a git hook, run `git clang-format` to format all files you
225+
touched.
226+
* You can run this as a **git pre-commit hook** to automatically format your delta regions when you
227+
commit a change. In the angular repo, run
222228

223229
```
224230
$ echo -e '#!/bin/sh\nexec git clang-format' > .git/hooks/pre-commit
@@ -237,7 +243,9 @@ Make sure it is executable. Then, in the angular repo, run
237243
- Program: [path to clang-format, try `$ echo $(npm config get prefix)/bin/clang-format`]
238244
- Parameters: `-i -style=file $FilePath$`
239245
- Working directory: `$ProjectFileDir$`
240-
246+
* `clang-format` integrations are also available for many popular editors (`vim`, `emacs`,
247+
`Sublime Text`, etc.).
248+
241249
## Project Information
242250

243251
### Folder structure

0 commit comments

Comments
 (0)