Skip to content

Commit 9096481

Browse files
committed
chore(lint): format tools dir
1 parent 5936624 commit 9096481

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+635
-656
lines changed

DEVELOPER.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -238,17 +238,17 @@ repository, allowing many tools and editors to share our settings.
238238

239239
To check the formatting of your code, run
240240

241-
gulp check-format
241+
gulp lint
242242

243-
Note that the continuous build on Travis runs `gulp enforce-format`. Unlike the `check-format` task,
244-
this will actually fail the build if files aren't formatted according to the style guide.
243+
Note that the continuous build on CircleCI will fail the build if files aren't formatted according
244+
to the style guide.
245245

246246
Your life will be easier if you include the formatter in your standard workflow. Otherwise, you'll
247247
likely forget to check the formatting, and waste time waiting for a build on Travis that fails due
248248
to some whitespace difference.
249249

250-
* Use `$(npm bin)/clang-format -i [file name]` to format a file (or multiple).
251-
* Use `gulp enforce-format` to check if your code is `clang-format` clean. This also gives
250+
* Use `gulp format` to format everything.
251+
* Use `gulp lint` to check if your code is `clang-format` clean. This also gives
252252
you a command line to format your code.
253253
* `clang-format` also includes a git hook, run `git clang-format` to format all files you
254254
touched.

tools/broccoli/angular_builder.ts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@ export type ProjectMap = {
1111
};
1212

1313
export type Options = {
14-
projects: ProjectMap;
15-
noTypeChecks: boolean;
16-
generateEs6: boolean;
17-
useBundles: boolean;
14+
projects: ProjectMap; noTypeChecks: boolean; generateEs6: boolean; useBundles: boolean;
1815
};
1916

2017
export interface AngularBuilderOptions {
@@ -133,14 +130,16 @@ export class AngularBuilder {
133130
writeBuildLog(result, name);
134131
return result;
135132
},
136-
(error): any => {
137-
// the build tree is the same during rebuilds, only leaf properties of the nodes change
138-
// so let's traverse it and get updated values for input/cache/output paths
139-
if (this.firstResult) {
140-
writeBuildLog(this.firstResult, name);
141-
}
142-
throw error;
143-
});
133+
(error):
134+
any => {
135+
// the build tree is the same during rebuilds, only leaf properties of the nodes
136+
// change
137+
// so let's traverse it and get updated values for input/cache/output paths
138+
if (this.firstResult) {
139+
writeBuildLog(this.firstResult, name);
140+
}
141+
throw error;
142+
});
144143
}
145144
}
146145

@@ -159,16 +158,17 @@ function writeBuildLog(result: BuildResult, name: string) {
159158
function broccoliNodeToBuildNode(broccoliNode: BroccoliNode): BuildNode {
160159
let tree = broccoliNode.tree.newStyleTree || broccoliNode.tree;
161160

162-
return new BuildNode(tree.description || (<any>tree.constructor).name,
163-
tree.inputPath ? [tree.inputPath] : tree.inputPaths, tree.cachePath,
164-
tree.outputPath, broccoliNode.selfTime / (1000 * 1000 * 1000),
165-
broccoliNode.totalTime / (1000 * 1000 * 1000),
166-
broccoliNode.subtrees.map(broccoliNodeToBuildNode));
161+
return new BuildNode(
162+
tree.description || (<any>tree.constructor).name,
163+
tree.inputPath ? [tree.inputPath] : tree.inputPaths, tree.cachePath, tree.outputPath,
164+
broccoliNode.selfTime / (1000 * 1000 * 1000), broccoliNode.totalTime / (1000 * 1000 * 1000),
165+
broccoliNode.subtrees.map(broccoliNodeToBuildNode));
167166
}
168167

169168

170169
class BuildNode {
171-
constructor(public pluginName: string, public inputPaths: string[], public cachePath: string,
172-
public outputPath: string, public selfTime: number, public totalTime: number,
173-
public inputNodes: BuildNode[]) {}
170+
constructor(
171+
public pluginName: string, public inputPaths: string[], public cachePath: string,
172+
public outputPath: string, public selfTime: number, public totalTime: number,
173+
public inputNodes: BuildNode[]) {}
174174
}

tools/broccoli/broccoli-check-imports.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ import {wrapDiffingPlugin, DiffingBroccoliPlugin, DiffResult} from './diffing-br
99
* This guarantees that platform-independent modules remain platoform-independent.
1010
*/
1111
class CheckImports implements DiffingBroccoliPlugin {
12-
static IMPORT_DECL_REGEXP = new RegExp(`^import[^;]+;`, "mg");
13-
static IMPORT_PATH_REGEXP = new RegExp(`['"]([^'"]+)+['"]`, "m");
12+
static IMPORT_DECL_REGEXP = new RegExp(`^import[^;]+;`, 'mg');
13+
static IMPORT_PATH_REGEXP = new RegExp(`['"]([^'"]+)+['"]`, 'm');
1414

1515
static ALLOWED_IMPORTS: {[s: string]: string[]} = {
16-
"angular2/src/core": ["angular2/src/facade"],
17-
"angular2/src/facade": ["rxjs"],
18-
"angular2/src/common": ["angular2/core", "angular2/src/facade"],
19-
"angular2/src/http": ["angular2/core", "angular2/src/facade", "rxjs"],
20-
"angular2/src/upgrade":
21-
["angular2/core", "angular2/src/facade", "angular2/platform/browser", "angular2/compiler"]
16+
'angular2/src/core': ['angular2/src/facade'],
17+
'angular2/src/facade': ['rxjs'],
18+
'angular2/src/common': ['angular2/core', 'angular2/src/facade'],
19+
'angular2/src/http': ['angular2/core', 'angular2/src/facade', 'rxjs'],
20+
'angular2/src/upgrade':
21+
['angular2/core', 'angular2/src/facade', 'angular2/platform/browser', 'angular2/compiler']
2222
//"angular2/src/render": [
2323
// "angular2/animate",
2424
// "angular2/core",
@@ -55,8 +55,8 @@ class CheckImports implements DiffingBroccoliPlugin {
5555

5656
private checkFilePath(filePath: string) {
5757
const sourceFilePath = path.join(this.inputPath, filePath);
58-
if (endsWith(sourceFilePath, ".ts") && fs.existsSync(sourceFilePath)) {
59-
const content = fs.readFileSync(sourceFilePath, "UTF-8");
58+
if (endsWith(sourceFilePath, '.ts') && fs.existsSync(sourceFilePath)) {
59+
const content = fs.readFileSync(sourceFilePath, 'UTF-8');
6060
const imports = content.match(CheckImports.IMPORT_DECL_REGEXP);
6161
if (imports) {
6262
return imports.filter(i => !this.isAllowedImport(filePath, i))
@@ -73,22 +73,22 @@ class CheckImports implements DiffingBroccoliPlugin {
7373
if (!res || res.length < 2) return true; // non-es6 import
7474
const importPath = res[1];
7575

76-
if (startsWith(importPath, "./") || startsWith(importPath, "../")) return true;
76+
if (startsWith(importPath, './') || startsWith(importPath, '../')) return true;
7777

7878
const c = CheckImports.ALLOWED_IMPORTS;
7979
for (var prop in c) {
8080
if (c.hasOwnProperty(prop) && startsWith(sourceFile, prop)) {
8181
const allowedPaths = c[prop];
8282
return startsWith(importPath, prop) ||
83-
allowedPaths.filter(p => startsWith(importPath, p)).length > 0;
83+
allowedPaths.filter(p => startsWith(importPath, p)).length > 0;
8484
}
8585
}
8686

8787
return true;
8888
}
8989

9090
private formatError(filePath: string, importPath: string): string {
91-
const i = importPath.replace(new RegExp(`\n`, 'g'), "\\n");
91+
const i = importPath.replace(new RegExp(`\n`, 'g'), '\\n');
9292
return `${filePath}: ${i}`;
9393
}
9494
}

tools/broccoli/broccoli-dartfmt.ts

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class DartFormatter implements DiffingBroccoliPlugin {
2424
private firstBuild: boolean = true;
2525

2626
constructor(public inputPath: string, public cachePath: string, options: AngularBuilderOptions) {
27-
if (!options.dartSDK) throw new Error("Missing Dart SDK");
27+
if (!options.dartSDK) throw new Error('Missing Dart SDK');
2828
this.DARTFMT = options.dartSDK.DARTFMT;
2929
this.verbose = options.logs.dartfmt;
3030
}
@@ -34,22 +34,21 @@ class DartFormatter implements DiffingBroccoliPlugin {
3434
let argsLength = 2;
3535
let argPackages: string[][] = [];
3636
let firstBuild = this.firstBuild;
37-
treeDiff.addedPaths.concat(treeDiff.changedPaths)
38-
.forEach((changedFile) => {
39-
let sourcePath = path.join(this.inputPath, changedFile);
40-
let destPath = path.join(this.cachePath, changedFile);
41-
if (!firstBuild && /\.dart$/.test(changedFile)) {
42-
if ((argsLength + destPath.length + 2) >= 0x2000) {
43-
// Win32 command line arguments length
44-
argPackages.push(args);
45-
args = ['-w'];
46-
argsLength = 2;
47-
}
48-
args.push(destPath);
49-
argsLength += destPath.length + 2;
50-
}
51-
fse.copySync(sourcePath, destPath);
52-
});
37+
treeDiff.addedPaths.concat(treeDiff.changedPaths).forEach((changedFile) => {
38+
let sourcePath = path.join(this.inputPath, changedFile);
39+
let destPath = path.join(this.cachePath, changedFile);
40+
if (!firstBuild && /\.dart$/.test(changedFile)) {
41+
if ((argsLength + destPath.length + 2) >= 0x2000) {
42+
// Win32 command line arguments length
43+
argPackages.push(args);
44+
args = ['-w'];
45+
argsLength = 2;
46+
}
47+
args.push(destPath);
48+
argsLength += destPath.length + 2;
49+
}
50+
fse.copySync(sourcePath, destPath);
51+
});
5352
treeDiff.removedPaths.forEach((removedFile) => {
5453
let destPath = path.join(this.cachePath, removedFile);
5554
fse.removeSync(destPath);
@@ -60,8 +59,7 @@ class DartFormatter implements DiffingBroccoliPlugin {
6059
}
6160

6261
let execute = (args: string[]) => {
63-
if (args.length < 2)
64-
return Promise.resolve();
62+
if (args.length < 2) return Promise.resolve();
6563
return new Promise<void>((resolve, reject) => {
6664
exec(this.DARTFMT + ' ' + args.join(' '), (err: Error, stdout: string, stderr: string) => {
6765
if (this.verbose) {

tools/broccoli/broccoli-dest-copy.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@ class DestCopy implements DiffingBroccoliPlugin {
1212

1313

1414
rebuild(treeDiff: DiffResult) {
15-
treeDiff.addedPaths.concat(treeDiff.changedPaths)
16-
.forEach((changedFilePath) => {
17-
var destFilePath = path.join(this.outputRoot, changedFilePath);
15+
treeDiff.addedPaths.concat(treeDiff.changedPaths).forEach((changedFilePath) => {
16+
var destFilePath = path.join(this.outputRoot, changedFilePath);
1817

19-
var destDirPath = path.dirname(destFilePath);
20-
fse.mkdirsSync(destDirPath);
21-
fse.copySync(path.join(this.inputPath, changedFilePath), destFilePath);
22-
});
18+
var destDirPath = path.dirname(destFilePath);
19+
fse.mkdirsSync(destDirPath);
20+
fse.copySync(path.join(this.inputPath, changedFilePath), destFilePath);
21+
});
2322

2423
treeDiff.removedPaths.forEach((removedFilePath) => {
2524
var destFilePath = path.join(this.outputRoot, removedFilePath);

tools/broccoli/broccoli-flatten.spec.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ describe('Flatten', () => {
88
afterEach(() => mockfs.restore());
99

1010
let flatten = (inputPaths: string) => new DiffingFlatten(inputPaths, 'output', null);
11-
let read = (path: string) => fs.readFileSync(path, {encoding: "utf-8"});
11+
let read = (path: string) => fs.readFileSync(path, {encoding: 'utf-8'});
1212
let rm = (path: string) => fs.unlinkSync(path);
1313
let write =
14-
(path: string, content: string) => { fs.writeFileSync(path, content, {encoding: "utf-8"}); }
14+
(path: string, content: string) => { fs.writeFileSync(path, content, {encoding: 'utf-8'}); }
1515

1616

1717
it('should flatten files and be incremental', () => {
@@ -67,7 +67,8 @@ describe('Flatten', () => {
6767
let differ = new TreeDiffer('testLabel', 'input');
6868
let flattenedTree = flatten('input');
6969
expect(() => flattenedTree.rebuild(differ.diffTree()))
70-
.toThrowError("Duplicate file 'file-1.txt' found in path 'dir1" + path.sep + "subdir-1" +
71-
path.sep + "file-1.txt'");
70+
.toThrowError(
71+
'Duplicate file \'file-1.txt\' found in path \'dir1' + path.sep + 'subdir-1' +
72+
path.sep + 'file-1.txt\'');
7273
});
7374
});

tools/broccoli/broccoli-flatten.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ var isWindows = process.platform === 'win32';
1414
* the associated changes.
1515
*/
1616
export class DiffingFlatten implements DiffingBroccoliPlugin {
17-
constructor(private inputPath: string, private cachePath: string,
18-
private options: AngularBuilderOptions) {}
17+
constructor(
18+
private inputPath: string, private cachePath: string,
19+
private options: AngularBuilderOptions) {}
1920

2021

2122
rebuild(treeDiff: DiffResult) {
@@ -39,8 +40,9 @@ export class DiffingFlatten implements DiffingBroccoliPlugin {
3940
if (!fs.existsSync(destFilePath)) {
4041
symlinkOrCopy(sourceFilePath, destFilePath);
4142
} else {
42-
throw new Error(`Duplicate file '${path.basename(changedFilePath)}' ` +
43-
`found in path '${changedFilePath}'`);
43+
throw new Error(
44+
`Duplicate file '${path.basename(changedFilePath)}' ` +
45+
`found in path '${changedFilePath}'`);
4446
}
4547
});
4648

tools/broccoli/broccoli-generate-for-test.ts

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,26 @@ import {wrapDiffingPlugin, DiffingBroccoliPlugin, DiffResult} from './diffing-br
1313
class GeneratorForTest implements DiffingBroccoliPlugin {
1414
private seenFiles: {[key: string]: boolean} = {};
1515

16-
constructor(private inputPath: string, private outputPath: string,
17-
private options: { files: string[], dartPath: string }) {}
16+
constructor(private inputPath: string, private outputPath: string, private options: {
17+
files: string[],
18+
dartPath: string
19+
}) {}
1820

1921
rebuild(treeDiff: DiffResult) {
2022
var matchedFiles: string[] = [];
2123
this.options.files.forEach(
2224
(file) => { matchedFiles = matchedFiles.concat(glob.sync(file, {cwd: this.inputPath})); });
23-
return Promise.all(matchedFiles.map((matchedFile) => {
24-
var inputFilePath = path.join(this.inputPath, matchedFile);
25-
var outputFilePath = path.join(this.outputPath, matchedFile);
25+
return Promise
26+
.all(matchedFiles.map((matchedFile) => {
27+
var inputFilePath = path.join(this.inputPath, matchedFile);
28+
var outputFilePath = path.join(this.outputPath, matchedFile);
2629

27-
var outputDirPath = path.dirname(outputFilePath);
28-
if (!fs.existsSync(outputDirPath)) {
29-
fse.mkdirpSync(outputDirPath);
30-
}
31-
return this.invokeGenerator(matchedFile, inputFilePath, outputFilePath)
32-
}))
30+
var outputDirPath = path.dirname(outputFilePath);
31+
if (!fs.existsSync(outputDirPath)) {
32+
fse.mkdirpSync(outputDirPath);
33+
}
34+
return this.invokeGenerator(matchedFile, inputFilePath, outputFilePath)
35+
}))
3336
.then(() => {
3437
var result = new DiffResult();
3538
matchedFiles.forEach((file) => {
@@ -44,8 +47,8 @@ class GeneratorForTest implements DiffingBroccoliPlugin {
4447
});
4548
}
4649

47-
private invokeGenerator(file: string, inputFilePath: string,
48-
outputFilePath: string): Promise<any> {
50+
private invokeGenerator(file: string, inputFilePath: string, outputFilePath: string):
51+
Promise<any> {
4952
return new Promise((resolve, reject) => {
5053
var args: string[];
5154
var vmPath: string;
@@ -62,15 +65,14 @@ class GeneratorForTest implements DiffingBroccoliPlugin {
6265
}
6366

6467
var stdoutStream = fs.createWriteStream(outputFilePath);
65-
var proc = childProcess.spawn(
66-
vmPath, args,
67-
{ stdio: ['ignore', 'pipe', 'inherit'],
68-
env: (<any>Object)['assign']({}, process.env, env)
69-
});
68+
var proc = childProcess.spawn(vmPath, args, {
69+
stdio: ['ignore', 'pipe', 'inherit'],
70+
env: (<any>Object)['assign']({}, process.env, env)
71+
});
7072
proc.on('error', function(code: any) {
7173
console.error(code);
72-
reject(new Error('Failed while generating code. Please run manually: ' + vmPath + ' ' +
73-
args.join(' ')));
74+
reject(new Error(
75+
'Failed while generating code. Please run manually: ' + vmPath + ' ' + args.join(' ')));
7476
});
7577
proc.on('close', function() {
7678
stdoutStream.close();

tools/broccoli/broccoli-lodash.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ const kDefaultOptions: LodashRendererOptions = {
2323
* the associated changes.
2424
*/
2525
export class LodashRenderer implements DiffingBroccoliPlugin {
26-
constructor(private inputPath: string, private cachePath: string,
27-
private options: LodashRendererOptions = kDefaultOptions) {}
26+
constructor(
27+
private inputPath: string, private cachePath: string,
28+
private options: LodashRendererOptions = kDefaultOptions) {}
2829

2930
rebuild(treeDiff: DiffResult) {
3031
let {encoding = 'utf-8', context = {}} = this.options;

tools/broccoli/broccoli-merge-trees.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ describe('MergeTrees', () => {
1515
}
1616

1717
let diffTrees = (differs: TreeDiffer[]): DiffResult[] => differs.map(tree => tree.diffTree());
18-
function read(path: string) { return fs.readFileSync(path, "utf-8"); }
18+
function read(path: string) { return fs.readFileSync(path, 'utf-8'); }
1919

2020
it('should copy the file from the right-most inputTree with overwrite=true', () => {
2121
let testDir: any = {

tools/broccoli/broccoli-merge-trees.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ export class MergeTrees implements DiffingBroccoliPlugin {
2424
public options: MergeTreesOptions;
2525
private firstBuild: boolean = true;
2626

27-
constructor(public inputPaths: string[], public cachePath: string,
28-
options: MergeTreesOptions = {}) {
27+
constructor(
28+
public inputPaths: string[], public cachePath: string, options: MergeTreesOptions = {}) {
2929
this.options = options || {};
3030
}
3131

0 commit comments

Comments
 (0)