Skip to content

Commit c1702d3

Browse files
committed
refactor: add no-floating-promises lint rule to project
With fixes; new now handles the parent initialize, visitor_spec now errors on rejection, and nothing in the writeI18nOutFile() function was async so removed the promise there entirely.
1 parent cb588b6 commit c1702d3

File tree

4 files changed

+29
-27
lines changed

4 files changed

+29
-27
lines changed

Diff for: packages/angular/cli/commands/new.ts

+13-12
Original file line numberDiff line numberDiff line change
@@ -39,24 +39,25 @@ export default class NewCommand extends SchematicCommand {
3939
private schematicName = 'ng-new';
4040

4141
private initialized = false;
42-
public initialize(options: any) {
42+
public async initialize(options: any) {
4343
if (this.initialized) {
44-
return Promise.resolve();
44+
return;
4545
}
46-
super.initialize(options);
46+
47+
await super.initialize(options);
48+
4749
this.initialized = true;
4850

4951
const collectionName = this.parseCollectionName(options);
5052

51-
return this.getOptions({
52-
schematicName: this.schematicName,
53-
collectionName,
54-
})
55-
.then((schematicOptions) => {
56-
this.options = this.options.concat(schematicOptions.options);
57-
const args = schematicOptions.arguments.map(arg => arg.name);
58-
this.arguments = this.arguments.concat(args);
59-
});
53+
const schematicOptions = await this.getOptions({
54+
schematicName: this.schematicName,
55+
collectionName,
56+
});
57+
58+
this.options = this.options.concat(schematicOptions.options);
59+
const args = schematicOptions.arguments.map(arg => arg.name);
60+
this.arguments = this.arguments.concat(args);
6061
}
6162

6263
public async run(options: any) {

Diff for: packages/angular_devkit/core/src/json/schema/visitor_spec.ts

+9-7
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@ function syncObs<T>(obs: Observable<T>): T {
1414
let value: T;
1515
let set = false;
1616

17-
obs.forEach(x => {
18-
if (set) {
19-
throw new Error('Multiple value.');
20-
}
21-
value = x;
22-
set = true;
23-
});
17+
obs
18+
.forEach(x => {
19+
if (set) {
20+
throw new Error('Multiple value.');
21+
}
22+
value = x;
23+
set = true;
24+
})
25+
.catch(err => fail(err));
2426

2527
if (!set) {
2628
throw new Error('Async observable.');

Diff for: packages/ngtools/webpack/src/angular_compiler_plugin.ts

+6-8
Original file line numberDiff line numberDiff line change
@@ -902,12 +902,10 @@ export class AngularCompilerPlugin {
902902
}
903903

904904
writeI18nOutFile() {
905-
function _recursiveMkDir(p: string): Promise<void> {
906-
if (fs.existsSync(p)) {
907-
return Promise.resolve();
908-
} else {
909-
return _recursiveMkDir(path.dirname(p))
910-
.then(() => fs.mkdirSync(p));
905+
function _recursiveMkDir(p: string) {
906+
if (!fs.existsSync(p)) {
907+
_recursiveMkDir(path.dirname(p));
908+
fs.mkdirSync(p);
911909
}
912910
}
913911

@@ -916,8 +914,8 @@ export class AngularCompilerPlugin {
916914
const i18nOutFilePath = path.resolve(this._basePath, this._compilerOptions.i18nOutFile);
917915
const i18nOutFileContent = this._compilerHost.readFile(i18nOutFilePath);
918916
if (i18nOutFileContent) {
919-
_recursiveMkDir(path.dirname(i18nOutFilePath))
920-
.then(() => fs.writeFileSync(i18nOutFilePath, i18nOutFileContent));
917+
_recursiveMkDir(path.dirname(i18nOutFilePath));
918+
fs.writeFileSync(i18nOutFilePath, i18nOutFileContent);
921919
}
922920
}
923921
}

Diff for: tslint.json

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"non-null-operator": true,
1010
"no-global-tslint-disable": true,
1111
"single-eof-line": true,
12+
"no-floating-promises": true,
1213

1314

1415
"no-implicit-dependencies": true,

0 commit comments

Comments
 (0)