diff --git a/DEVELOPER.md b/DEVELOPER.md index d118014af8..c4cb6484df 100644 --- a/DEVELOPER.md +++ b/DEVELOPER.md @@ -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 diff --git a/gulpfile.js b/gulpfile.js index 9019d0dc57..eb79611512 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -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); }); }); diff --git a/npm-shrinkwrap.clean.json b/npm-shrinkwrap.clean.json index b206194f57..c4ce50266f 100644 --- a/npm-shrinkwrap.clean.json +++ b/npm-shrinkwrap.clean.json @@ -3934,7 +3934,7 @@ } }, "gulp-clang-format": { - "version": "1.0.13", + "version": "1.0.14", "dependencies": { "gulp-util": { "version": "3.0.4", diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index 59cfc98328..d2adb8a34d 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -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", diff --git a/package.json b/package.json index 13c93925ff..85b2c5e6e3 100644 --- a/package.json +++ b/package.json @@ -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",