From 463a7894ae7c61ef95c5226884dfdb91d97344c7 Mon Sep 17 00:00:00 2001 From: Jeremy Elbourn Date: Mon, 28 Jan 2019 16:13:29 -0800 Subject: [PATCH] build: `gulp format` only changed lines by default (#28411) Changes `gulp format` to format only changed lines by default (`gulp format:changed`) and introduces a new task, `gulp format:all` to format all source files. Since formatting only changed lines should be the more common action, it makes more sense as the shorter default. PR Close #28411 --- docs/DEVELOPER.md | 4 ++-- gulpfile.js | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/docs/DEVELOPER.md b/docs/DEVELOPER.md index f52fcac79b..cfa316457c 100644 --- a/docs/DEVELOPER.md +++ b/docs/DEVELOPER.md @@ -105,8 +105,8 @@ Angular uses [clang-format](http://clang.llvm.org/docs/ClangFormat.html) to form If the source code is not properly formatted, the CI will fail and the PR can not be merged. You can automatically format your code by running: -- `gulp format`: format all source code -- `gulp format:changed`: re-format only edited source code. +- `gulp format`: re-format only edited source code. +- `gulp format:all`: format _all_ source code A better way is to set up your IDE to format the changed file on each file save. diff --git a/gulpfile.js b/gulpfile.js index 36ae7dc114..e77ab05b4f 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -27,11 +27,25 @@ function loadTask(fileName, taskName) { return task(gulp); } +// Check source code for formatting errors in all source files. gulp.task('format:enforce', loadTask('format', 'enforce')); -gulp.task('format', loadTask('format', 'format')); + +// Format all source files. +gulp.task('format:all', loadTask('format', 'format')); + +// Format only untracked source code files. gulp.task('format:untracked', loadTask('format', 'format-untracked')); + +// Format only the changed, tracked source code files. gulp.task('format:diff', loadTask('format', 'format-diff')); + +// Format only changed lines based on the diff from the provided --branch +// argument (or `master` by default). gulp.task('format:changed', ['format:untracked', 'format:diff']); + +// Alias for `format:changed` that formerly formatted all files. +gulp.task('format', ['format:changed']); + gulp.task('lint', ['format:enforce', 'validate-commit-messages', 'tslint']); gulp.task('tslint', ['tools:build'], loadTask('lint')); gulp.task('validate-commit-messages', loadTask('validate-commit-message'));