mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-17 11:03:53 +08:00
build: update/cleanup tslint rules & fix errors
This commit is contained in:
parent
a9e25fffae
commit
d202480a17
packages
angular/cli/models
angular_devkit
build_angular/src/dev-server
core
schematics/src
ngtools/webpack/src
schematics
angular
app-shell
e2e
migrations/update-6
universal
utility
update/update
rules
scripts
tslint.json@ -20,8 +20,7 @@ import {
|
||||
tags,
|
||||
} from '@angular-devkit/core';
|
||||
import { NodeJsSyncHost, createConsoleLogger } from '@angular-devkit/core/node';
|
||||
import { of } from 'rxjs';
|
||||
import { from } from 'rxjs';
|
||||
import { from, of } from 'rxjs';
|
||||
import { concatMap, map, tap, toArray } from 'rxjs/operators';
|
||||
import { Command, Option } from './command';
|
||||
import { WorkspaceLoader } from './workspace-loader';
|
||||
|
@ -16,17 +16,20 @@ export async function convertSchemaToOptions(schema: string): Promise<Option[]>
|
||||
}
|
||||
|
||||
function getOptions(schemaText: string, onlyRootProperties = true): Promise<Option[]> {
|
||||
// TODO: refactor promise to an observable then use `.toPromise()`
|
||||
return new Promise((resolve, reject) => {
|
||||
// TODO: Use devkit core's visitJsonSchema
|
||||
return new Promise((resolve) => {
|
||||
const fullSchema = parseJson(schemaText);
|
||||
if (!isJsonObject(fullSchema)) {
|
||||
return Promise.resolve([]);
|
||||
}
|
||||
const traverseOptions = {};
|
||||
const options: Option[] = [];
|
||||
function postCallback(schema: JsonObject,
|
||||
jsonPointer: string,
|
||||
rootSchema: string,
|
||||
parentJsonPointer: string,
|
||||
_rootSchema: string,
|
||||
_parentJsonPointer: string,
|
||||
parentKeyword: string,
|
||||
parentSchema: string,
|
||||
_parentSchema: string,
|
||||
property: string) {
|
||||
if (parentKeyword === 'properties') {
|
||||
let includeOption = true;
|
||||
@ -43,7 +46,7 @@ function getOptions(schemaText: string, onlyRootProperties = true): Promise<Opti
|
||||
}
|
||||
let $default: OptionSmartDefault | undefined = undefined;
|
||||
if (schema.$default !== null && isJsonObject(schema.$default)) {
|
||||
$default = <OptionSmartDefault> schema.$default;
|
||||
$default = schema.$default as OptionSmartDefault;
|
||||
}
|
||||
let required = false;
|
||||
if (typeof schema.required === 'boolean') {
|
||||
@ -51,7 +54,7 @@ function getOptions(schemaText: string, onlyRootProperties = true): Promise<Opti
|
||||
}
|
||||
let aliases: string[] | undefined = undefined;
|
||||
if (typeof schema.aliases === 'object' && Array.isArray(schema.aliases)) {
|
||||
aliases = <string[]> schema.aliases;
|
||||
aliases = schema.aliases as string[];
|
||||
}
|
||||
let format: string | undefined = undefined;
|
||||
if (typeof schema.format === 'string') {
|
||||
@ -86,7 +89,7 @@ function getOptions(schemaText: string, onlyRootProperties = true): Promise<Opti
|
||||
|
||||
const callbacks = { post: postCallback };
|
||||
|
||||
jsonSchemaTraverse(<object> fullSchema, traverseOptions, callbacks);
|
||||
jsonSchemaTraverse(fullSchema, traverseOptions, callbacks);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -14,8 +14,7 @@ import {
|
||||
} from '@angular-devkit/architect';
|
||||
import { WebpackDevServerBuilder } from '@angular-devkit/build-webpack';
|
||||
import { Path, getSystemPath, resolve, tags, virtualFs } from '@angular-devkit/core';
|
||||
import { existsSync, readFileSync } from 'fs';
|
||||
import * as fs from 'fs';
|
||||
import { Stats, existsSync, readFileSync } from 'fs';
|
||||
import * as path from 'path';
|
||||
import { Observable, throwError } from 'rxjs';
|
||||
import { concatMap, map, tap } from 'rxjs/operators';
|
||||
@ -69,7 +68,7 @@ export class DevServerBuilder implements Builder<DevServerBuilderOptions> {
|
||||
const options = builderConfig.options;
|
||||
const root = this.context.workspace.root;
|
||||
const projectRoot = resolve(root, builderConfig.root);
|
||||
const host = new virtualFs.AliasHost(this.context.host as virtualFs.Host<fs.Stats>);
|
||||
const host = new virtualFs.AliasHost(this.context.host as virtualFs.Host<Stats>);
|
||||
const webpackDevServerBuilder = new WebpackDevServerBuilder({ ...this.context, host });
|
||||
let browserOptions: BrowserBuilderSchema;
|
||||
let first = true;
|
||||
@ -175,7 +174,7 @@ export class DevServerBuilder implements Builder<DevServerBuilderOptions> {
|
||||
buildWebpackConfig(
|
||||
root: Path,
|
||||
projectRoot: Path,
|
||||
host: virtualFs.Host<fs.Stats>,
|
||||
host: virtualFs.Host<Stats>,
|
||||
browserOptions: BrowserBuilderSchema,
|
||||
) {
|
||||
const browserBuilder = new BrowserBuilder(this.context);
|
||||
|
@ -336,11 +336,11 @@ export class NodeJsSyncHost implements virtualFs.Host<fs.Stats> {
|
||||
}
|
||||
|
||||
isDirectory(path: Path): Observable<boolean> {
|
||||
// tslint:disable-next-line:non-null-operator
|
||||
// tslint:disable-next-line:no-non-null-assertion
|
||||
return this.stat(path) !.pipe(map(stat => stat.isDirectory()));
|
||||
}
|
||||
isFile(path: Path): Observable<boolean> {
|
||||
// tslint:disable-next-line:non-null-operator
|
||||
// tslint:disable-next-line:no-non-null-assertion
|
||||
return this.stat(path) !.pipe(map(stat => stat.isFile()));
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
// tslint:disable:no-any
|
||||
// tslint:disable:non-null-operator
|
||||
// tslint:disable:no-non-null-assertion
|
||||
// tslint:disable:no-implicit-dependencies
|
||||
import { normalize, virtualFs } from '@angular-devkit/core';
|
||||
import { NodeJsAsyncHost, NodeJsSyncHost } from '@angular-devkit/core/node';
|
||||
|
@ -28,7 +28,7 @@ function syncObs<T>(obs: Observable<T>): T {
|
||||
throw new Error('Async observable.');
|
||||
}
|
||||
|
||||
return value !; // tslint:disable-line:non-null-operator
|
||||
return value !; // tslint:disable-line:no-non-null-assertion
|
||||
}
|
||||
|
||||
|
||||
|
@ -74,7 +74,7 @@ export class AliasHost<StatsT extends object = {}> extends ResolverHost<StatsT>
|
||||
maybeAlias = join(maybeAlias, ...remaining);
|
||||
}
|
||||
// Allow non-null-operator because we know sp.length > 0 (condition on while).
|
||||
remaining.unshift(sp.pop() !); // tslint:disable-line:non-null-operator
|
||||
remaining.unshift(sp.pop() !); // tslint:disable-line:no-non-null-assertion
|
||||
}
|
||||
|
||||
return maybeAlias || path;
|
||||
|
@ -6,7 +6,7 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
// tslint:disable:no-implicit-dependencies
|
||||
// tslint:disable:non-null-operator
|
||||
// tslint:disable:no-non-null-assertion
|
||||
import { fragment, normalize } from '@angular-devkit/core';
|
||||
import { stringToFileBuffer } from './buffer';
|
||||
import { SimpleMemoryHost } from './memory';
|
||||
|
@ -53,7 +53,7 @@ export class SyncDelegateHost<T extends object = {}> {
|
||||
// The non-null operation is to work around `void` type. We don't allow to return undefined
|
||||
// but ResultT could be void, which is undefined in JavaScript, so this doesn't change the
|
||||
// behaviour.
|
||||
// tslint:disable-next-line:non-null-operator
|
||||
// tslint:disable-next-line:no-non-null-assertion
|
||||
return result !;
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
// tslint:disable:non-null-operator
|
||||
// tslint:disable:no-non-null-assertion
|
||||
import { logging } from '@angular-devkit/core';
|
||||
import { of as observableOf } from 'rxjs';
|
||||
import { chain } from '../rules/base';
|
||||
|
@ -5,8 +5,7 @@
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
import { FilePredicate, MergeStrategy } from './tree/interface';
|
||||
import { Tree as TreeInterface } from './tree/interface';
|
||||
import { FilePredicate, MergeStrategy, Tree as TreeInterface } from './tree/interface';
|
||||
import { branch, empty, merge, optimize, partition } from './tree/static';
|
||||
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
// tslint:disable:no-implicit-dependencies
|
||||
// tslint:disable:non-null-operator
|
||||
// tslint:disable:no-non-null-assertion
|
||||
import { Path, virtualFs } from '@angular-devkit/core';
|
||||
import {
|
||||
HostTree,
|
||||
|
@ -5,7 +5,7 @@
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
// tslint:disable:non-null-operator
|
||||
// tslint:disable:no-non-null-assertion
|
||||
// tslint:disable:no-any
|
||||
// tslint:disable:no-implicit-dependencies
|
||||
import { MergeStrategy } from '@angular-devkit/schematics';
|
||||
|
@ -5,7 +5,7 @@
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
// tslint:disable:non-null-operator
|
||||
// tslint:disable:no-non-null-assertion
|
||||
import { of as observableOf } from 'rxjs';
|
||||
import { SchematicContext } from '../engine/interface';
|
||||
import { HostTree } from '../tree/host-tree';
|
||||
|
@ -5,7 +5,7 @@
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
// tslint:disable:non-null-operator
|
||||
// tslint:disable:no-non-null-assertion
|
||||
import { of as observableOf } from 'rxjs';
|
||||
import { SchematicContext } from '../engine/interface';
|
||||
import { HostTree } from '../tree/host-tree';
|
||||
|
@ -5,7 +5,7 @@
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
// tslint:disable:non-null-operator
|
||||
// tslint:disable:no-non-null-assertion
|
||||
import { normalize } from '@angular-devkit/core';
|
||||
import { Tree } from './interface';
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
// tslint:disable:non-null-operator
|
||||
// tslint:disable:no-non-null-assertion
|
||||
import { PathIsFileException, normalize, virtualFs } from '@angular-devkit/core';
|
||||
import { testTreeVisit } from './common_spec';
|
||||
import { FileSystemTree } from './filesystem';
|
||||
|
@ -22,12 +22,12 @@ export enum MergeStrategy {
|
||||
Error = 1 << 0,
|
||||
|
||||
// Only content conflicts are overwritten.
|
||||
ContentOnly = MergeStrategy.AllowOverwriteConflict,
|
||||
ContentOnly = AllowOverwriteConflict,
|
||||
|
||||
// Overwrite everything with the latest change.
|
||||
Overwrite = MergeStrategy.AllowOverwriteConflict
|
||||
+ MergeStrategy.AllowCreationConflict
|
||||
+ MergeStrategy.AllowDeleteConflict,
|
||||
Overwrite = AllowOverwriteConflict
|
||||
+ AllowCreationConflict
|
||||
+ AllowDeleteConflict,
|
||||
}
|
||||
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
// tslint:disable:non-null-operator no-big-function
|
||||
// tslint:disable:no-non-null-assertion no-big-function
|
||||
import { normalize, virtualFs } from '@angular-devkit/core';
|
||||
import { FileAlreadyExistException, FileDoesNotExistException } from '../exception/exception';
|
||||
import { testTreeVisit } from './common_spec';
|
||||
|
@ -413,7 +413,7 @@ export class AngularCompilerPlugin {
|
||||
genDir: '',
|
||||
}),
|
||||
// TODO: fix compiler-cli typings; entryModule should not be string, but also optional.
|
||||
// tslint:disable-next-line:non-null-operator
|
||||
// tslint:disable-next-line:no-non-null-assertion
|
||||
entryModule: this._entryModule !,
|
||||
});
|
||||
timeEnd('AngularCompilerPlugin._getLazyRoutesFromNgtools');
|
||||
|
@ -62,7 +62,7 @@ function getServerModulePath(
|
||||
if (!expNode) {
|
||||
return null;
|
||||
}
|
||||
const relativePath = <ts.StringLiteral> (<ts.ExportDeclaration> expNode).moduleSpecifier;
|
||||
const relativePath = (expNode as ts.ExportDeclaration).moduleSpecifier as ts.StringLiteral;
|
||||
const modulePath = normalize(`/${project.root}/src/${relativePath.text}.ts`);
|
||||
|
||||
return modulePath;
|
||||
@ -113,7 +113,7 @@ function getBootstrapComponentPath(
|
||||
const metadataNode = getDecoratorMetadata(moduleSource, 'NgModule', '@angular/core')[0];
|
||||
const bootstrapProperty = getMetadataProperty(metadataNode, 'bootstrap');
|
||||
|
||||
const arrLiteral = (<ts.PropertyAssignment> bootstrapProperty)
|
||||
const arrLiteral = (bootstrapProperty as ts.PropertyAssignment)
|
||||
.initializer as ts.ArrayLiteralExpression;
|
||||
|
||||
const componentSymbol = arrLiteral.elements[0].getText();
|
||||
@ -124,7 +124,7 @@ function getBootstrapComponentPath(
|
||||
return findNode(imp, ts.SyntaxKind.Identifier, componentSymbol);
|
||||
})
|
||||
.map((imp: ts.ImportDeclaration) => {
|
||||
const pathStringLiteral = <ts.StringLiteral> imp.moduleSpecifier;
|
||||
const pathStringLiteral = imp.moduleSpecifier as ts.StringLiteral;
|
||||
|
||||
return pathStringLiteral.text;
|
||||
})[0];
|
||||
|
@ -5,8 +5,7 @@
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
import { strings, tags } from '@angular-devkit/core';
|
||||
import { experimental } from '@angular-devkit/core';
|
||||
import { experimental, strings, tags } from '@angular-devkit/core';
|
||||
import {
|
||||
Rule,
|
||||
SchematicContext,
|
||||
|
@ -517,7 +517,7 @@ function extractProjectsConfig(
|
||||
}
|
||||
|
||||
return newItems;
|
||||
}, <string[]> []);
|
||||
}, [] as string[]);
|
||||
|
||||
// Tslint target
|
||||
const lintOptions: JsonObject = {
|
||||
|
@ -221,7 +221,7 @@ export default function (options: UniversalOptions): Rule {
|
||||
template({
|
||||
...strings,
|
||||
...options as object,
|
||||
stripTsExtension: (s: string) => { return s.replace(/\.ts$/, ''); },
|
||||
stripTsExtension: (s: string) => s.replace(/\.ts$/, ''),
|
||||
}),
|
||||
move(join(normalize(clientProject.root), 'src')),
|
||||
]);
|
||||
@ -230,7 +230,7 @@ export default function (options: UniversalOptions): Rule {
|
||||
template({
|
||||
...strings,
|
||||
...options as object,
|
||||
stripTsExtension: (s: string) => { return s.replace(/\.ts$/, ''); },
|
||||
stripTsExtension: (s: string) => s.replace(/\.ts$/, ''),
|
||||
outDir,
|
||||
tsConfigExtends,
|
||||
rootInSrc,
|
||||
|
@ -555,7 +555,7 @@ export function isImported(source: ts.SourceFile,
|
||||
.filter(node => node.kind === ts.SyntaxKind.ImportDeclaration)
|
||||
.filter((imp: ts.ImportDeclaration) => imp.moduleSpecifier.kind === ts.SyntaxKind.StringLiteral)
|
||||
.filter((imp: ts.ImportDeclaration) => {
|
||||
return (<ts.StringLiteral> imp.moduleSpecifier).text === importPath;
|
||||
return (imp.moduleSpecifier as ts.StringLiteral).text === importPath;
|
||||
})
|
||||
.filter((imp: ts.ImportDeclaration) => {
|
||||
if (!imp.importClause) {
|
||||
|
@ -67,7 +67,7 @@ export function findBootstrapModulePath(host: Tree, mainPath: string): string {
|
||||
return findNode(imp, ts.SyntaxKind.Identifier, bootstrapModule.getText());
|
||||
})
|
||||
.map((imp: ts.ImportDeclaration) => {
|
||||
const modulePathStringLiteral = <ts.StringLiteral> imp.moduleSpecifier;
|
||||
const modulePathStringLiteral = imp.moduleSpecifier as ts.StringLiteral;
|
||||
|
||||
return modulePathStringLiteral.text;
|
||||
})[0];
|
||||
|
@ -243,7 +243,7 @@ function _performUpdate(
|
||||
|
||||
const toInstall = [...infoMap.values()]
|
||||
.map(x => [x.name, x.target, x.installed])
|
||||
// tslint:disable-next-line:non-null-operator
|
||||
// tslint:disable-next-line:no-non-null-assertion
|
||||
.filter(([name, target, installed]) => {
|
||||
return !!name && !!target && !!installed;
|
||||
}) as [string, PackageVersionInfo, PackageVersionInfo][];
|
||||
|
@ -1,36 +0,0 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google Inc. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
import * as Lint from 'tslint';
|
||||
import * as ts from 'typescript';
|
||||
|
||||
|
||||
export class Rule extends Lint.Rules.AbstractRule {
|
||||
public static metadata: Lint.IRuleMetadata = {
|
||||
ruleName: 'non-null-operator',
|
||||
type: 'typescript',
|
||||
description: `Ensure the NonNull operator (!) can be used or not.`,
|
||||
rationale: 'strictNullChecks are meant to avoid issues, which the non-null operator removes '
|
||||
+ 'if used too frequently. Please use the non-null operator responsibly.',
|
||||
options: null,
|
||||
optionsDescription: `Not configurable.`,
|
||||
typescriptOnly: false,
|
||||
};
|
||||
|
||||
public static FAILURE_STRING = 'The Non-Null operator `!` is illegal.';
|
||||
|
||||
public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
|
||||
return this.applyWithWalker(new Walker(sourceFile, this.getOptions()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class Walker extends Lint.RuleWalker {
|
||||
visitNonNullExpression(node: ts.NonNullExpression): void {
|
||||
this.addFailureAt(node.getStart(), node.getWidth(), Rule.FAILURE_STRING);
|
||||
}
|
||||
}
|
@ -10,7 +10,6 @@ import { logging } from '@angular-devkit/core';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import * as semver from 'semver';
|
||||
import { ReleaseType } from 'semver';
|
||||
import { packages } from '../lib/packages';
|
||||
|
||||
|
||||
@ -81,7 +80,7 @@ function _upgrade(release: string, force: boolean, logger: logging.Logger) {
|
||||
}
|
||||
}
|
||||
} else if (dirty || release !== 'patch') {
|
||||
newVersion = semver.inc(version, release as ReleaseType);
|
||||
newVersion = semver.inc(version, release as semver.ReleaseType);
|
||||
}
|
||||
|
||||
let message = '';
|
||||
|
10
tslint.json
10
tslint.json
@ -14,7 +14,6 @@
|
||||
"//04": "custom rules defined in dist/rules/**",
|
||||
"defocus": true,
|
||||
"import-groups": true,
|
||||
"non-null-operator": true,
|
||||
"no-global-tslint-disable": true,
|
||||
"single-eof-line": true,
|
||||
"//05": "==================================================================================================",
|
||||
@ -38,7 +37,6 @@
|
||||
"no-unthrown-error": true,
|
||||
"no-use-of-empty-return-value": true,
|
||||
"no-useless-increment": true,
|
||||
"no-useless-intersection": true,
|
||||
|
||||
"//09": "These rules are part of the code smell detection section of tslint-sonarts",
|
||||
"no-dead-store": true,
|
||||
@ -47,6 +45,14 @@
|
||||
|
||||
"//11": "==================================================================================================",
|
||||
"//12": "base tslint rules",
|
||||
"arrow-return-shorthand": true,
|
||||
"no-duplicate-imports": true,
|
||||
"no-angle-bracket-type-assertion": true,
|
||||
"no-conditional-assignment": true,
|
||||
"no-non-null-assertion": true,
|
||||
"no-unnecessary-qualifier": true,
|
||||
"no-string-throw": true,
|
||||
"encoding": true,
|
||||
"no-floating-promises": true,
|
||||
"no-implicit-dependencies": true,
|
||||
"no-import-side-effect": [true, {"ignore-module": "^(?!rxjs\/)"}],
|
||||
|
Loading…
x
Reference in New Issue
Block a user