Skip to content

Commit 1aefab6

Browse files
committed
Enforce clang-format formatting on all JS files
This change reformats all files according to clang-format rules (the same that Angular JS has) and forces the files to comply with the formatting.
1 parent 95e7260 commit 1aefab6

26 files changed

+374
-337
lines changed

.clang-format

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Project configuration for the clang-format tool.
2+
# Learn more at: http://clang.llvm.org/docs/ClangFormat.html
3+
Language: JavaScript
4+
BasedOnStyle: Google
5+
ColumnLimit: 100

build/backend.js

+30-23
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,16 @@ import goCommand from './gocommand';
2828
* directory.
2929
*/
3030
gulp.task('backend', function(doneFn) {
31-
goCommand([
32-
'build',
33-
// Install dependencies to speed up subsequent compilations.
34-
'-i',
35-
'-o', path.join(conf.paths.serve, conf.backend.binaryName),
36-
conf.backend.packageName,
37-
], doneFn);
31+
goCommand(
32+
[
33+
'build',
34+
// Install dependencies to speed up subsequent compilations.
35+
'-i',
36+
'-o',
37+
path.join(conf.paths.serve, conf.backend.binaryName),
38+
conf.backend.packageName,
39+
],
40+
doneFn);
3841
});
3942

4043

@@ -50,20 +53,24 @@ gulp.task('backend:prod', function(doneFn) {
5053

5154
// Delete output binary first. This is required because prod build does not override it.
5255
del(outputBinaryPath)
53-
.then(function() {
54-
goCommand([
55-
'build',
56-
'-a',
57-
'-installsuffix', 'cgo',
58-
'-o', outputBinaryPath,
59-
conf.backend.packageName,
60-
], doneFn, {
61-
// Disable cgo package. Required to run on scratch docker image.
62-
CGO_ENABLED: '0',
63-
// Scratch docker image is linux.
64-
GOOS: 'linux',
65-
});
66-
}, function(error) {
67-
doneFn(error);
68-
});
56+
.then(
57+
function() {
58+
goCommand(
59+
[
60+
'build',
61+
'-a',
62+
'-installsuffix',
63+
'cgo',
64+
'-o',
65+
outputBinaryPath,
66+
conf.backend.packageName,
67+
],
68+
doneFn, {
69+
// Disable cgo package. Required to run on scratch docker image.
70+
CGO_ENABLED: '0',
71+
// Scratch docker image is linux.
72+
GOOS: 'linux',
73+
});
74+
},
75+
function(error) { doneFn(error); });
6976
});

build/build.js

+31-32
Original file line numberDiff line numberDiff line change
@@ -45,54 +45,53 @@ gulp.task('build', ['backend:prod', 'build-frontend']);
4545
* 3. CSS and JS assets are suffixed with version hash.
4646
* 4. Everything is saved in the dist directory.
4747
*/
48-
gulp.task('build-frontend', ['assets', 'index:prod'], function () {
48+
gulp.task('build-frontend', ['assets', 'index:prod'], function() {
4949
let htmlFilter = gulpFilter('*.html', {restore: true});
5050
let vendorCssFilter = gulpFilter('**/vendor.css', {restore: true});
5151
let vendorJsFilter = gulpFilter('**/vendor.js', {restore: true});
5252
let assets;
5353

5454
return gulp.src(path.join(conf.paths.prodTmp, '*.html'))
55-
.pipe(assets = gulpUseref.assets({
56-
searchPath: [
57-
// To resolve local paths.
58-
conf.paths.prodTmp,
59-
// To resolve bower_components/... paths.
60-
conf.paths.base,
61-
],
62-
}))
63-
.pipe(vendorCssFilter)
64-
.pipe(gulpMinifyCss())
65-
.pipe(vendorCssFilter.restore)
66-
.pipe(vendorJsFilter)
67-
.pipe(gulpUglify({preserveComments: uglifySaveLicense}))
68-
.pipe(vendorJsFilter.restore)
69-
.pipe(gulpRev())
70-
.pipe(assets.restore())
71-
.pipe(gulpUseref({searchPath: [conf.paths.prodTmp]}))
72-
.pipe(gulpRevReplace())
73-
.pipe(htmlFilter)
74-
.pipe(gulpMinifyHtml({
75-
empty: true,
76-
spare: true,
77-
quotes: true,
78-
}))
79-
.pipe(htmlFilter.restore)
80-
.pipe(gulp.dest(conf.paths.distPublic));
55+
.pipe(assets = gulpUseref.assets({
56+
searchPath: [
57+
// To resolve local paths.
58+
conf.paths.prodTmp,
59+
// To resolve bower_components/... paths.
60+
conf.paths.base,
61+
],
62+
}))
63+
.pipe(vendorCssFilter)
64+
.pipe(gulpMinifyCss())
65+
.pipe(vendorCssFilter.restore)
66+
.pipe(vendorJsFilter)
67+
.pipe(gulpUglify({preserveComments: uglifySaveLicense}))
68+
.pipe(vendorJsFilter.restore)
69+
.pipe(gulpRev())
70+
.pipe(assets.restore())
71+
.pipe(gulpUseref({searchPath: [conf.paths.prodTmp]}))
72+
.pipe(gulpRevReplace())
73+
.pipe(htmlFilter)
74+
.pipe(gulpMinifyHtml({
75+
empty: true,
76+
spare: true,
77+
quotes: true,
78+
}))
79+
.pipe(htmlFilter.restore)
80+
.pipe(gulp.dest(conf.paths.distPublic));
8181
});
8282

8383

8484
/**
8585
* Copies assets to the dist directory.
8686
*/
87-
gulp.task('assets', function () {
87+
gulp.task('assets', function() {
8888
return gulp.src(path.join(conf.paths.assets, '/**/*'), {base: conf.paths.app})
89-
.pipe(gulp.dest(conf.paths.distPublic));
89+
.pipe(gulp.dest(conf.paths.distPublic));
9090
});
9191

9292

9393
/**
9494
* Cleans all build artifacts.
9595
*/
96-
gulp.task('clean', function () {
97-
return del([conf.paths.dist, conf.paths.goWorkspace, conf.paths.tmp]);
98-
});
96+
gulp.task(
97+
'clean', function() { return del([conf.paths.dist, conf.paths.goWorkspace, conf.paths.tmp]); });

build/check.js

+39-9
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* @fileoverview Gulp tasks for checking and validating the code or a commit.
1717
*/
1818
import gulp from 'gulp';
19+
import gulpClangFormat from 'gulp-clang-format';
1920
import gulpEslint from 'gulp-eslint';
2021
import path from 'path';
2122

@@ -30,16 +31,45 @@ import conf from './conf';
3031
**/
3132
gulp.task('check', ['lint', 'build', 'test', 'integration-test:prod']);
3233

34+
35+
/**
36+
* Lints all projects code files.
37+
* // TODO(bryk): Also lint Go files here.
38+
*/
39+
gulp.task('lint', ['lint-javascript', 'check-javascript-format']);
40+
41+
42+
/**
43+
* Lints all projects JavaScript files using ESLint. This includes frontend source code, as well as,
44+
* build scripts.
45+
*/
46+
gulp.task('lint-javascript', function() {
47+
return gulp.src([path.join(conf.paths.src, '**/*.js'), path.join(conf.paths.build, '**/*.js')])
48+
// Attach lint output to the eslint property of the file.
49+
.pipe(gulpEslint())
50+
// Output the lint results to the console.
51+
.pipe(gulpEslint.format())
52+
// Exit with an error code (1) on a lint error.
53+
.pipe(gulpEslint.failOnError());
54+
});
55+
56+
3357
/**
34-
* Lints all projects code files. This includes frontend source code, as well as, build scripts.
58+
* Checks whether project's JavaScript files are formatted according to clang-format style.
3559
*/
36-
gulp.task('lint', function() {
37-
// TODO(bryk): Also lint Go files here.
60+
gulp.task('check-javascript-format', function() {
3861
return gulp.src([path.join(conf.paths.src, '**/*.js'), path.join(conf.paths.build, '**/*.js')])
39-
// Attach lint output to the eslint property of the file.
40-
.pipe(gulpEslint())
41-
// Output the lint results to the console.
42-
.pipe(gulpEslint.format())
43-
// Exit with an error code (1) on a lint error.
44-
.pipe(gulpEslint.failOnError());
62+
.pipe(gulpClangFormat.checkFormat('file', undefined, {verbose: true, fail: true}));
63+
});
64+
65+
66+
/**
67+
* Formats all project's JavaScript files using clang-format.
68+
*/
69+
gulp.task('format-javascript', function() {
70+
return gulp.src(
71+
[path.join(conf.paths.src, '**/*.js'), path.join(conf.paths.build, '**/*.js')],
72+
{base: conf.paths.base})
73+
.pipe(gulpClangFormat.format('file'))
74+
.pipe(gulp.dest(conf.paths.base));
4575
});

0 commit comments

Comments
 (0)