Skip to content

Commit 08e1762

Browse files
hanslclydin
authored andcommitted
refactor: add tslint-sonarts and a lot of tslint rules
This should clean up the code a bit. Note: at first I added the no-useless-cast rule, but after getting frustrated with it (as it has many false positive), I decided to remove the rule but some useless casts were removed so I let those in the PR.
1 parent dd460ff commit 08e1762

File tree

45 files changed

+2471
-2360
lines changed

Some content is hidden

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

45 files changed

+2471
-2360
lines changed

package-lock.json

Lines changed: 2319 additions & 2306 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@
130130
"tree-kill": "^1.2.0",
131131
"ts-node": "^5.0.0",
132132
"tslint": "^5.9.1",
133+
"tslint-sonarts": "^1.7.0",
133134
"tsutils": "~2.22.2",
134135
"typescript": "~2.7.2",
135136
"uglifyjs-webpack-plugin": "^1.2.5",

packages/angular/cli/commands/version.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ export default class VersionCommand extends Command {
2222
public readonly options: Option[] = [];
2323

2424
public run() {
25-
let angularCoreVersion = '';
26-
const angularSameAsCore: string[] = [];
2725
const pkg = require(path.resolve(__dirname, '..', 'package.json'));
2826
let projPkg;
2927
try {
@@ -95,6 +93,8 @@ export default class VersionCommand extends Command {
9593

9694
ngCliVersion = `local (v${pkg.version}, branch: ${gitBranch})`;
9795
}
96+
let angularCoreVersion = '';
97+
const angularSameAsCore: string[] = [];
9898

9999
if (projPkg) {
100100
// Filter all angular versions that are the same as core.
@@ -107,6 +107,9 @@ export default class VersionCommand extends Command {
107107
delete versions[angularPackage];
108108
}
109109
}
110+
111+
// Make sure we list them in alphabetical order.
112+
angularSameAsCore.sort();
110113
}
111114
}
112115

@@ -128,7 +131,7 @@ export default class VersionCommand extends Command {
128131
Node: ${process.versions.node}
129132
OS: ${process.platform} ${process.arch}
130133
Angular: ${angularCoreVersion}
131-
... ${angularSameAsCore.sort().reduce<string[]>((acc, name) => {
134+
... ${angularSameAsCore.reduce<string[]>((acc, name) => {
132135
// Perform a simple word wrap around 60.
133136
if (acc.length == 0) {
134137
return [name];

packages/angular/cli/tasks/npm-install.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export type NpmInstall = (packageName: string,
1515
logger: logging.Logger,
1616
packageManager: string,
1717
projectRoot: string,
18-
save?: boolean) => void;
18+
save?: boolean) => Promise<void>;
1919

2020
export default async function (packageName: string,
2121
logger: logging.Logger,

packages/angular/cli/utilities/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ export function getWorkspaceRaw(
119119
throw new Error('Invalid JSON');
120120
}
121121

122-
return [ast as JsonAstObject, configPath];
122+
return [ast, configPath];
123123
}
124124

125125
export function validateWorkspace(json: JsonObject) {

packages/angular_devkit/architect/testing/test-project-host.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,15 @@ export class TestProjectHost extends NodeJsSyncHost {
3434
throw new Error('TestProjectHost must be initialized before being used.');
3535
}
3636

37-
// tslint:disable-next-line:non-null-operator
38-
return this._currentRoot!;
37+
return this._currentRoot;
3938
}
4039

4140
scopedSync(): virtualFs.SyncDelegateHost<Stats> {
4241
if (this._currentRoot === null || this._scopedSyncHost === null) {
4342
throw new Error('TestProjectHost must be initialized before being used.');
4443
}
4544

46-
// tslint:disable-next-line:non-null-operator
47-
return this._scopedSyncHost!;
45+
return this._scopedSyncHost;
4846
}
4947

5048
initialize(): Observable<void> {
@@ -100,7 +98,7 @@ export class TestProjectHost extends NodeJsSyncHost {
10098
}
10199

102100
writeMultipleFiles(files: { [path: string]: string | ArrayBufferLike | Buffer }): void {
103-
Object.keys(files).map(fileName => {
101+
Object.keys(files).forEach(fileName => {
104102
let content = files[fileName];
105103
if (typeof content == 'string') {
106104
content = virtualFs.stringToFileBuffer(content);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,13 +290,13 @@ export class DevServerBuilder implements Builder<DevServerBuilderOptions> {
290290
let sslKey: string | undefined = undefined;
291291
let sslCert: string | undefined = undefined;
292292
if (options.sslKey) {
293-
const keyPath = path.resolve(root, options.sslKey as string);
293+
const keyPath = path.resolve(root, options.sslKey);
294294
if (existsSync(keyPath)) {
295295
sslKey = readFileSync(keyPath, 'utf-8');
296296
}
297297
}
298298
if (options.sslCert) {
299-
const certPath = path.resolve(root, options.sslCert as string);
299+
const certPath = path.resolve(root, options.sslCert);
300300
if (existsSync(certPath)) {
301301
sslCert = readFileSync(certPath, 'utf-8');
302302
}

packages/angular_devkit/build_angular/src/karma/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export class KarmaBuilder implements Builder<KarmaBuilderSchema> {
8383

8484
// TODO: inside the configs, always use the project root and not the workspace root.
8585
// Until then we pretend the app root is relative (``) but the same as `projectRoot`.
86-
(karmaOptions.buildWebpack.options as any).root = ''; // tslint:disable-line:no-any
86+
karmaOptions.buildWebpack.options.root = '';
8787

8888
// Assign additional karmaConfig options to the local ngapp config
8989
karmaOptions.configFile = karmaConfig;
@@ -112,7 +112,7 @@ export class KarmaBuilder implements Builder<KarmaBuilderSchema> {
112112
) {
113113
let wco: WebpackConfigOptions;
114114

115-
const tsConfigPath = getSystemPath(resolve(root, normalize(options.tsConfig as string)));
115+
const tsConfigPath = getSystemPath(resolve(root, normalize(options.tsConfig)));
116116
const tsConfig = readTsconfig(tsConfigPath);
117117

118118
const projectTs = requireProjectModule(getSystemPath(projectRoot), 'typescript') as typeof ts;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ export class ServerBuilder implements Builder<BuildWebpackServerSchema> {
106106

107107
if (wco.buildOptions.main || wco.buildOptions.polyfills) {
108108
const typescriptConfigPartial = wco.buildOptions.aot
109-
? getAotConfig(wco, host as virtualFs.Host<Stats>)
110-
: getNonAotConfig(wco, host as virtualFs.Host<Stats>);
109+
? getAotConfig(wco, host)
110+
: getNonAotConfig(wco, host);
111111
webpackConfigs.push(typescriptConfigPartial);
112112
}
113113

packages/angular_devkit/build_angular/test/browser/rebuild_spec_large.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +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:no-big-function
89

910
import { DefaultTimeout, TestLogger, runTargetSpec } from '@angular-devkit/architect/testing';
1011
import { join, normalize, virtualFs } from '@angular-devkit/core';

0 commit comments

Comments
 (0)