chore(build): improve messaging when using clang-format

This commit is contained in:
Alex Eagle 2015-05-22 09:56:31 -07:00
parent 15f1eb28a2
commit 16447ce75c
5 changed files with 24 additions and 10 deletions

View File

@ -197,21 +197,34 @@ Angular specific command line options when running protractor (e.g. force gc, ..
## Formatting
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.
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.
To check the formatting of your code, run
gulp check-format
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.
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.
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.
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.
* **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
* **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
```
$ echo -e '#!/bin/sh\nexec git clang-format' > .git/hooks/pre-commit
$ chmod u+x !$
```
* **WebStorm** can run clang-format on the current file.
1. Under Preferences, open Tools > External Tools.
1. Plus icon to Create Tool

View File

@ -227,7 +227,8 @@ gulp.task('check-format', function() {
gulp.task('enforce-format', function() {
return doCheckFormat().on('warning', function(e) {
console.log("ERROR: Some files need formatting");
console.log("ERROR: You forgot to run clang-format on your change.");
console.log("See https://github.com/angular/angular/blob/master/DEVELOPER.md#formatting");
process.exit(1);
});
});

View File

@ -3934,7 +3934,7 @@
}
},
"gulp-clang-format": {
"version": "1.0.13",
"version": "1.0.14",
"dependencies": {
"gulp-util": {
"version": "3.0.4",

6
npm-shrinkwrap.json generated
View File

@ -6073,9 +6073,9 @@
}
},
"gulp-clang-format": {
"version": "1.0.13",
"from": "https://registry.npmjs.org/gulp-clang-format/-/gulp-clang-format-1.0.13.tgz",
"resolved": "https://registry.npmjs.org/gulp-clang-format/-/gulp-clang-format-1.0.13.tgz",
"version": "1.0.14",
"from": "https://registry.npmjs.org/gulp-clang-format/-/gulp-clang-format-1.0.14.tgz",
"resolved": "https://registry.npmjs.org/gulp-clang-format/-/gulp-clang-format-1.0.14.tgz",
"dependencies": {
"gulp-util": {
"version": "3.0.4",

View File

@ -64,7 +64,7 @@
"gulp": "^3.8.8",
"gulp-autoprefixer": "^2.1.0",
"gulp-changed": "^1.0.0",
"gulp-clang-format": "^1.0.13",
"gulp-clang-format": "^1.0.14",
"gulp-concat": "^2.5.2",
"gulp-connect": "~1.0.5",
"gulp-load-plugins": "^0.7.1",