Skip to content

Commit d202480

Browse files
clydinhansl
authored andcommitted
build: update/cleanup tslint rules & fix errors
1 parent a9e25ff commit d202480

File tree

30 files changed

+55
-87
lines changed

30 files changed

+55
-87
lines changed

packages/angular/cli/models/architect-command.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ import {
2020
tags,
2121
} from '@angular-devkit/core';
2222
import { NodeJsSyncHost, createConsoleLogger } from '@angular-devkit/core/node';
23-
import { of } from 'rxjs';
24-
import { from } from 'rxjs';
23+
import { from, of } from 'rxjs';
2524
import { concatMap, map, tap, toArray } from 'rxjs/operators';
2625
import { Command, Option } from './command';
2726
import { WorkspaceLoader } from './workspace-loader';

packages/angular/cli/models/json-schema.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,20 @@ export async function convertSchemaToOptions(schema: string): Promise<Option[]>
1616
}
1717

1818
function getOptions(schemaText: string, onlyRootProperties = true): Promise<Option[]> {
19-
// TODO: refactor promise to an observable then use `.toPromise()`
20-
return new Promise((resolve, reject) => {
19+
// TODO: Use devkit core's visitJsonSchema
20+
return new Promise((resolve) => {
2121
const fullSchema = parseJson(schemaText);
22+
if (!isJsonObject(fullSchema)) {
23+
return Promise.resolve([]);
24+
}
2225
const traverseOptions = {};
2326
const options: Option[] = [];
2427
function postCallback(schema: JsonObject,
2528
jsonPointer: string,
26-
rootSchema: string,
27-
parentJsonPointer: string,
29+
_rootSchema: string,
30+
_parentJsonPointer: string,
2831
parentKeyword: string,
29-
parentSchema: string,
32+
_parentSchema: string,
3033
property: string) {
3134
if (parentKeyword === 'properties') {
3235
let includeOption = true;
@@ -43,15 +46,15 @@ function getOptions(schemaText: string, onlyRootProperties = true): Promise<Opti
4346
}
4447
let $default: OptionSmartDefault | undefined = undefined;
4548
if (schema.$default !== null && isJsonObject(schema.$default)) {
46-
$default = <OptionSmartDefault> schema.$default;
49+
$default = schema.$default as OptionSmartDefault;
4750
}
4851
let required = false;
4952
if (typeof schema.required === 'boolean') {
5053
required = schema.required;
5154
}
5255
let aliases: string[] | undefined = undefined;
5356
if (typeof schema.aliases === 'object' && Array.isArray(schema.aliases)) {
54-
aliases = <string[]> schema.aliases;
57+
aliases = schema.aliases as string[];
5558
}
5659
let format: string | undefined = undefined;
5760
if (typeof schema.format === 'string') {
@@ -86,7 +89,7 @@ function getOptions(schemaText: string, onlyRootProperties = true): Promise<Opti
8689

8790
const callbacks = { post: postCallback };
8891

89-
jsonSchemaTraverse(<object> fullSchema, traverseOptions, callbacks);
92+
jsonSchemaTraverse(fullSchema, traverseOptions, callbacks);
9093
});
9194
}
9295

packages/angular_devkit/build_angular/src/dev-server/index.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ import {
1414
} from '@angular-devkit/architect';
1515
import { WebpackDevServerBuilder } from '@angular-devkit/build-webpack';
1616
import { Path, getSystemPath, resolve, tags, virtualFs } from '@angular-devkit/core';
17-
import { existsSync, readFileSync } from 'fs';
18-
import * as fs from 'fs';
17+
import { Stats, existsSync, readFileSync } from 'fs';
1918
import * as path from 'path';
2019
import { Observable, throwError } from 'rxjs';
2120
import { concatMap, map, tap } from 'rxjs/operators';
@@ -69,7 +68,7 @@ export class DevServerBuilder implements Builder<DevServerBuilderOptions> {
6968
const options = builderConfig.options;
7069
const root = this.context.workspace.root;
7170
const projectRoot = resolve(root, builderConfig.root);
72-
const host = new virtualFs.AliasHost(this.context.host as virtualFs.Host<fs.Stats>);
71+
const host = new virtualFs.AliasHost(this.context.host as virtualFs.Host<Stats>);
7372
const webpackDevServerBuilder = new WebpackDevServerBuilder({ ...this.context, host });
7473
let browserOptions: BrowserBuilderSchema;
7574
let first = true;
@@ -175,7 +174,7 @@ export class DevServerBuilder implements Builder<DevServerBuilderOptions> {
175174
buildWebpackConfig(
176175
root: Path,
177176
projectRoot: Path,
178-
host: virtualFs.Host<fs.Stats>,
177+
host: virtualFs.Host<Stats>,
179178
browserOptions: BrowserBuilderSchema,
180179
) {
181180
const browserBuilder = new BrowserBuilder(this.context);

packages/angular_devkit/core/node/host.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,11 +336,11 @@ export class NodeJsSyncHost implements virtualFs.Host<fs.Stats> {
336336
}
337337

338338
isDirectory(path: Path): Observable<boolean> {
339-
// tslint:disable-next-line:non-null-operator
339+
// tslint:disable-next-line:no-non-null-assertion
340340
return this.stat(path) !.pipe(map(stat => stat.isDirectory()));
341341
}
342342
isFile(path: Path): Observable<boolean> {
343-
// tslint:disable-next-line:non-null-operator
343+
// tslint:disable-next-line:no-non-null-assertion
344344
return this.stat(path) !.pipe(map(stat => stat.isFile()));
345345
}
346346

packages/angular_devkit/core/node/host_spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88
// tslint:disable:no-any
9-
// tslint:disable:non-null-operator
9+
// tslint:disable:no-non-null-assertion
1010
// tslint:disable:no-implicit-dependencies
1111
import { normalize, virtualFs } from '@angular-devkit/core';
1212
import { NodeJsAsyncHost, NodeJsSyncHost } from '@angular-devkit/core/node';

packages/angular_devkit/core/src/json/schema/visitor_spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function syncObs<T>(obs: Observable<T>): T {
2828
throw new Error('Async observable.');
2929
}
3030

31-
return value !; // tslint:disable-line:non-null-operator
31+
return value !; // tslint:disable-line:no-non-null-assertion
3232
}
3333

3434

packages/angular_devkit/core/src/virtual-fs/host/alias.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export class AliasHost<StatsT extends object = {}> extends ResolverHost<StatsT>
7474
maybeAlias = join(maybeAlias, ...remaining);
7575
}
7676
// Allow non-null-operator because we know sp.length > 0 (condition on while).
77-
remaining.unshift(sp.pop() !); // tslint:disable-line:non-null-operator
77+
remaining.unshift(sp.pop() !); // tslint:disable-line:no-non-null-assertion
7878
}
7979

8080
return maybeAlias || path;

packages/angular_devkit/core/src/virtual-fs/host/memory_spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88
// tslint:disable:no-implicit-dependencies
9-
// tslint:disable:non-null-operator
9+
// tslint:disable:no-non-null-assertion
1010
import { fragment, normalize } from '@angular-devkit/core';
1111
import { stringToFileBuffer } from './buffer';
1212
import { SimpleMemoryHost } from './memory';

packages/angular_devkit/core/src/virtual-fs/host/sync.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export class SyncDelegateHost<T extends object = {}> {
5353
// The non-null operation is to work around `void` type. We don't allow to return undefined
5454
// but ResultT could be void, which is undefined in JavaScript, so this doesn't change the
5555
// behaviour.
56-
// tslint:disable-next-line:non-null-operator
56+
// tslint:disable-next-line:no-non-null-assertion
5757
return result !;
5858
}
5959

packages/angular_devkit/schematics/src/engine/schematic_spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8-
// tslint:disable:non-null-operator
8+
// tslint:disable:no-non-null-assertion
99
import { logging } from '@angular-devkit/core';
1010
import { of as observableOf } from 'rxjs';
1111
import { chain } from '../rules/base';

packages/angular_devkit/schematics/src/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8-
import { FilePredicate, MergeStrategy } from './tree/interface';
9-
import { Tree as TreeInterface } from './tree/interface';
8+
import { FilePredicate, MergeStrategy, Tree as TreeInterface } from './tree/interface';
109
import { branch, empty, merge, optimize, partition } from './tree/static';
1110

1211

packages/angular_devkit/schematics/src/rules/base_spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88
// tslint:disable:no-implicit-dependencies
9-
// tslint:disable:non-null-operator
9+
// tslint:disable:no-non-null-assertion
1010
import { Path, virtualFs } from '@angular-devkit/core';
1111
import {
1212
HostTree,

packages/angular_devkit/schematics/src/rules/call_spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8-
// tslint:disable:non-null-operator
8+
// tslint:disable:no-non-null-assertion
99
// tslint:disable:no-any
1010
// tslint:disable:no-implicit-dependencies
1111
import { MergeStrategy } from '@angular-devkit/schematics';

packages/angular_devkit/schematics/src/rules/move_spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8-
// tslint:disable:non-null-operator
8+
// tslint:disable:no-non-null-assertion
99
import { of as observableOf } from 'rxjs';
1010
import { SchematicContext } from '../engine/interface';
1111
import { HostTree } from '../tree/host-tree';

packages/angular_devkit/schematics/src/rules/rename_spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8-
// tslint:disable:non-null-operator
8+
// tslint:disable:no-non-null-assertion
99
import { of as observableOf } from 'rxjs';
1010
import { SchematicContext } from '../engine/interface';
1111
import { HostTree } from '../tree/host-tree';

packages/angular_devkit/schematics/src/tree/common_spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8-
// tslint:disable:non-null-operator
8+
// tslint:disable:no-non-null-assertion
99
import { normalize } from '@angular-devkit/core';
1010
import { Tree } from './interface';
1111

packages/angular_devkit/schematics/src/tree/filesystem_spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8-
// tslint:disable:non-null-operator
8+
// tslint:disable:no-non-null-assertion
99
import { PathIsFileException, normalize, virtualFs } from '@angular-devkit/core';
1010
import { testTreeVisit } from './common_spec';
1111
import { FileSystemTree } from './filesystem';

packages/angular_devkit/schematics/src/tree/interface.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ export enum MergeStrategy {
2222
Error = 1 << 0,
2323

2424
// Only content conflicts are overwritten.
25-
ContentOnly = MergeStrategy.AllowOverwriteConflict,
25+
ContentOnly = AllowOverwriteConflict,
2626

2727
// Overwrite everything with the latest change.
28-
Overwrite = MergeStrategy.AllowOverwriteConflict
29-
+ MergeStrategy.AllowCreationConflict
30-
+ MergeStrategy.AllowDeleteConflict,
28+
Overwrite = AllowOverwriteConflict
29+
+ AllowCreationConflict
30+
+ AllowDeleteConflict,
3131
}
3232

3333

packages/angular_devkit/schematics/src/tree/virtual_spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8-
// tslint:disable:non-null-operator no-big-function
8+
// tslint:disable:no-non-null-assertion no-big-function
99
import { normalize, virtualFs } from '@angular-devkit/core';
1010
import { FileAlreadyExistException, FileDoesNotExistException } from '../exception/exception';
1111
import { testTreeVisit } from './common_spec';

packages/ngtools/webpack/src/angular_compiler_plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ export class AngularCompilerPlugin {
413413
genDir: '',
414414
}),
415415
// TODO: fix compiler-cli typings; entryModule should not be string, but also optional.
416-
// tslint:disable-next-line:non-null-operator
416+
// tslint:disable-next-line:no-non-null-assertion
417417
entryModule: this._entryModule !,
418418
});
419419
timeEnd('AngularCompilerPlugin._getLazyRoutesFromNgtools');

packages/schematics/angular/app-shell/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ function getServerModulePath(
6262
if (!expNode) {
6363
return null;
6464
}
65-
const relativePath = <ts.StringLiteral> (<ts.ExportDeclaration> expNode).moduleSpecifier;
65+
const relativePath = (expNode as ts.ExportDeclaration).moduleSpecifier as ts.StringLiteral;
6666
const modulePath = normalize(`/${project.root}/src/${relativePath.text}.ts`);
6767

6868
return modulePath;
@@ -113,7 +113,7 @@ function getBootstrapComponentPath(
113113
const metadataNode = getDecoratorMetadata(moduleSource, 'NgModule', '@angular/core')[0];
114114
const bootstrapProperty = getMetadataProperty(metadataNode, 'bootstrap');
115115

116-
const arrLiteral = (<ts.PropertyAssignment> bootstrapProperty)
116+
const arrLiteral = (bootstrapProperty as ts.PropertyAssignment)
117117
.initializer as ts.ArrayLiteralExpression;
118118

119119
const componentSymbol = arrLiteral.elements[0].getText();
@@ -124,7 +124,7 @@ function getBootstrapComponentPath(
124124
return findNode(imp, ts.SyntaxKind.Identifier, componentSymbol);
125125
})
126126
.map((imp: ts.ImportDeclaration) => {
127-
const pathStringLiteral = <ts.StringLiteral> imp.moduleSpecifier;
127+
const pathStringLiteral = imp.moduleSpecifier as ts.StringLiteral;
128128

129129
return pathStringLiteral.text;
130130
})[0];

packages/schematics/angular/e2e/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8-
import { strings, tags } from '@angular-devkit/core';
9-
import { experimental } from '@angular-devkit/core';
8+
import { experimental, strings, tags } from '@angular-devkit/core';
109
import {
1110
Rule,
1211
SchematicContext,

packages/schematics/angular/migrations/update-6/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ function extractProjectsConfig(
517517
}
518518

519519
return newItems;
520-
}, <string[]> []);
520+
}, [] as string[]);
521521

522522
// Tslint target
523523
const lintOptions: JsonObject = {

packages/schematics/angular/universal/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ export default function (options: UniversalOptions): Rule {
221221
template({
222222
...strings,
223223
...options as object,
224-
stripTsExtension: (s: string) => { return s.replace(/\.ts$/, ''); },
224+
stripTsExtension: (s: string) => s.replace(/\.ts$/, ''),
225225
}),
226226
move(join(normalize(clientProject.root), 'src')),
227227
]);
@@ -230,7 +230,7 @@ export default function (options: UniversalOptions): Rule {
230230
template({
231231
...strings,
232232
...options as object,
233-
stripTsExtension: (s: string) => { return s.replace(/\.ts$/, ''); },
233+
stripTsExtension: (s: string) => s.replace(/\.ts$/, ''),
234234
outDir,
235235
tsConfigExtends,
236236
rootInSrc,

packages/schematics/angular/utility/ast-utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ export function isImported(source: ts.SourceFile,
555555
.filter(node => node.kind === ts.SyntaxKind.ImportDeclaration)
556556
.filter((imp: ts.ImportDeclaration) => imp.moduleSpecifier.kind === ts.SyntaxKind.StringLiteral)
557557
.filter((imp: ts.ImportDeclaration) => {
558-
return (<ts.StringLiteral> imp.moduleSpecifier).text === importPath;
558+
return (imp.moduleSpecifier as ts.StringLiteral).text === importPath;
559559
})
560560
.filter((imp: ts.ImportDeclaration) => {
561561
if (!imp.importClause) {

packages/schematics/angular/utility/ng-ast-utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export function findBootstrapModulePath(host: Tree, mainPath: string): string {
6767
return findNode(imp, ts.SyntaxKind.Identifier, bootstrapModule.getText());
6868
})
6969
.map((imp: ts.ImportDeclaration) => {
70-
const modulePathStringLiteral = <ts.StringLiteral> imp.moduleSpecifier;
70+
const modulePathStringLiteral = imp.moduleSpecifier as ts.StringLiteral;
7171

7272
return modulePathStringLiteral.text;
7373
})[0];

packages/schematics/update/update/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ function _performUpdate(
243243

244244
const toInstall = [...infoMap.values()]
245245
.map(x => [x.name, x.target, x.installed])
246-
// tslint:disable-next-line:non-null-operator
246+
// tslint:disable-next-line:no-non-null-assertion
247247
.filter(([name, target, installed]) => {
248248
return !!name && !!target && !!installed;
249249
}) as [string, PackageVersionInfo, PackageVersionInfo][];

rules/nonNullOperatorRule.ts

Lines changed: 0 additions & 36 deletions
This file was deleted.

0 commit comments

Comments
 (0)