Skip to content

Commit 0aaba03

Browse files
committed
refactor: add linting rules and conform to them
Removed a lot of any usage, but the rule will not be activated right now. I need more time to fix the code.
1 parent 303cdec commit 0aaba03

Some content is hidden

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

85 files changed

+625
-640
lines changed

lib/packages.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88
'use strict';
99

10+
import {JsonObject} from '@angular-devkit/core';
1011
import * as glob from 'glob';
1112
import * as path from 'path';
1213

@@ -23,7 +24,7 @@ export interface PackageInfo {
2324
main: string;
2425
dist: string;
2526
build: string;
26-
packageJson: any;
27+
packageJson: JsonObject;
2728
dependencies: string[];
2829
}
2930
export type PackageMap = { [name: string]: PackageInfo };
@@ -49,17 +50,20 @@ function loadPackageJson(p: string) {
4950

5051
case 'keywords':
5152
const a = pkg[key] || [];
52-
const b = Object.keys(root[key].concat(a).reduce((acc: any, curr: string) => {
53-
acc[curr] = true;
54-
return acc;
55-
}, {}));
53+
const b = Object.keys(
54+
root[key].concat(a).reduce((acc: {[k: string]: boolean}, curr: string) => {
55+
acc[curr] = true;
56+
57+
return acc;
58+
}, {}));
5659
pkg[key] = b;
5760
break;
5861

5962
default:
6063
pkg[key] = root[key];
6164
}
6265
}
66+
6367
return pkg;
6468
}
6569

@@ -103,6 +107,7 @@ export const packages: PackageMap =
103107
name,
104108
packageJson,
105109
};
110+
106111
return packages;
107112
}, {});
108113

package-lock.json

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

packages/_benchmark/src/benchmark.ts

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,27 @@
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-
declare let global: any;
8+
declare const global: {
9+
benchmarkReporter: {
10+
reportBenchmark: Function,
11+
},
12+
};
913

1014

1115
const kNanosecondsPerSeconds = 1e9;
16+
const kBenchmarkIterationMaxCount = 10000;
17+
const kBenchmarkTimeoutInMsec = 5000;
18+
const kWarmupIterationCount = 10;
19+
const kTopMetricCount = 5;
1220

1321

1422
function _run(fn: () => void, collector: number[]) {
1523
const timeout = Date.now();
16-
for (let i = 0; i < 10000 && (Date.now() - timeout) < 5000; i++) {
24+
// Gather the first 5 seconds runs, or kMaxNumberOfIterations runs whichever comes first
25+
// (soft timeout).
26+
for (let i = 0;
27+
i < kBenchmarkIterationMaxCount && (Date.now() - timeout) < kBenchmarkTimeoutInMsec;
28+
i++) {
1729
// Start time.
1830
const start = process.hrtime();
1931
fn();
@@ -36,35 +48,34 @@ function _stats(metrics: number[]) {
3648
const average = total / metrics.length;
3749

3850
return {
39-
slowest: metrics.slice(-5).reverse(),
40-
fastest: metrics.slice(0, 5),
51+
fastest: metrics.slice(0, kTopMetricCount),
52+
slowest: metrics.reverse().slice(0, kTopMetricCount),
4153
mean,
42-
average
54+
average,
4355
};
4456
}
4557

4658

4759
export function benchmark(name: string, fn: () => void, base?: () => void) {
4860
it(name + ' (time in nanoseconds)', (done) => {
4961
process.nextTick(() => {
50-
for (let i = 0; i < 100; i++) {
62+
for (let i = 0; i < kWarmupIterationCount; i++) {
5163
// Warm it up.
5264
fn();
5365
}
5466

55-
const reporter: any = global.benchmarkReporter;
67+
const reporter = global.benchmarkReporter;
5668
const metrics: number[] = [];
5769
const baseMetrics: number[] = [];
5870

59-
// Gather the first 5 seconds runs, or 10000 runs whichever comes first (soft timeout).
6071
_run(fn, metrics);
6172
if (base) {
6273
_run(base, baseMetrics);
6374
}
6475

6576
reporter.reportBenchmark({
6677
..._stats(metrics),
67-
base: base ? _stats(baseMetrics) : null
78+
base: base ? _stats(baseMetrics) : null,
6879
});
6980

7081
done();

packages/_schematics_cli/src/cli.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
import {
1818
FileSystemHost,
1919
FileSystemSchematicDesc,
20-
NodeModulesEngineHost
20+
NodeModulesEngineHost,
2121
} from '@angular-devkit/schematics-tools';
2222
import {SchemaClassFactory} from '@ngtools/json-schema';
2323
import * as minimist from 'minimist';
@@ -87,7 +87,7 @@ function parseSchematicName(str: string | null): { collection: string, schematic
8787

8888
/** Parse the command line. */
8989
const argv = minimist(process.argv.slice(2), {
90-
boolean: [ 'dry-run', 'force', 'help', 'list-schematics', 'verbose' ]
90+
boolean: [ 'dry-run', 'force', 'help', 'list-schematics', 'verbose' ],
9191
});
9292
/** Create the DevKit Logger used through the CLI. */
9393
const logger = createLogger(argv['verbose']);
@@ -99,7 +99,7 @@ if (argv.help) {
9999
/** Get the collection an schematic name from the first argument. */
100100
const {
101101
collection: collectionName,
102-
schematic: schematicName
102+
schematic: schematicName,
103103
} = parseSchematicName(argv._.shift() || null);
104104

105105

@@ -111,12 +111,14 @@ const engineHost = new NodeModulesEngineHost();
111111
const engine = new SchematicEngine(engineHost);
112112

113113
// Add support for schemaJson.
114-
engineHost.registerOptionsTransform((schematic: FileSystemSchematicDesc, options: any) => {
114+
engineHost.registerOptionsTransform((schematic: FileSystemSchematicDesc, options: {}) => {
115115
if (schematic.schema) {
116-
const SchemaMetaClass = SchemaClassFactory<any>(schematic.schemaJson !);
116+
const SchemaMetaClass = SchemaClassFactory<{}>(schematic.schemaJson !);
117117
const schemaClass = new SchemaMetaClass(options);
118+
118119
return schemaClass.$$root();
119120
}
121+
120122
return options;
121123
});
122124

@@ -215,11 +217,12 @@ schematic.call(argv, host)
215217
if (dryRun || error) {
216218
return Observable.of(tree);
217219
}
220+
218221
return fsSink.commit(tree).ignoreElements().concat(Observable.of(tree));
219222
})
220223
.subscribe({
221224
error(err: Error) {
222225
logger.fatal(err.toString());
223226
process.exit(1);
224-
}
227+
},
225228
});

packages/angular_devkit/core/BUILD

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,4 @@ ts_library(
3232
# @typings: jasmine
3333
],
3434
tsconfig = "//:tsconfig.json",
35-
module_name = "@angular-devkit/core",
36-
module_root = "src"
3735
)

0 commit comments

Comments
 (0)