Skip to content

Commit ae60661

Browse files
committed
feat(dev-infra):: add lint rule to enforce no-implicit-override abstract members
TypeScript introduced a new flag called `noImplicitOverride` as part of TypeScript v4.3. This flag introduces a new keyword called `override` that can be applied to members which override declarations from a base class. This helps with code health as TS will report an error if e.g. the base class changes the method name but the override would still have the old method name. Similarly, if the base class removes the method completely, TS would complain that the memeber with `override` no longer overrides any method. A similar concept applies to abstract methods, with the exception that TypeScript's builtin `noImplicitOverride` option does not flag members which are implemented as part of an abstract class. We want to enforce this as a best-practice in the repository as adding `override` to such implemented members will cause TS to complain if an abstract member is removed, but still implemented by derived classes. More details: microsoft/TypeScript#44457.
1 parent 3473061 commit ae60661

File tree

8 files changed

+34
-7
lines changed

8 files changed

+34
-7
lines changed

dev-infra/BUILD.bazel

+1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ pkg_npm(
7878
"//dev-infra/benchmark/driver-utilities",
7979
"//dev-infra/commit-message",
8080
"//dev-infra/ts-circular-dependencies",
81+
"//dev-infra/tslint-rules",
8182
],
8283
)
8384

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"test-fixme-ivy-aot": "bazelisk test --config=ivy --build_tag_filters=-no-ivy-aot --test_tag_filters=-no-ivy-aot",
3030
"list-fixme-ivy-targets": "bazelisk query --output=label 'attr(\"tags\", \"\\[.*fixme-ivy.*\\]\", //...) except kind(\"sh_binary\", //...) except kind(\"devmode_js_sources\", //...)' | sort",
3131
"lint": "yarn -s tslint && yarn -s ng-dev format changed --check",
32-
"tslint": "tsc -p tools/tsconfig.json && tslint -c tslint.json \"+(dev-infra|packages|modules|scripts|tools)/**/*.+(js|ts)\"",
32+
"tslint": "tslint -c tslint.json --project tsconfig-tslint.json",
3333
"public-api:check": "node goldens/public-api/manage.js test",
3434
"public-api:update": "node goldens/public-api/manage.js accept",
3535
"symbol-extractor:check": "node tools/symbol-extractor/run_all_symbols_extractor_tests.js test",

tools/contributing-stats/get-data.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,8 @@ async function run(date: string) {
237237
console.info(['Username', ...buildQueryAndParams('', date).labels].join(','));
238238

239239
for (const username of allOrgMembers) {
240-
const results = await graphql(buildQueryAndParams(username, date).query.toString());
240+
const results: [{issueCount: number}] =
241+
await graphql(buildQueryAndParams(username, date).query.toString());
241242
const values = Object.values(results).map(result => `${result.issueCount}`);
242243
console.info([username, ...values].join(','));
243244
}

tools/size-tracking/size_tracker.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export class SizeTracker {
9494
filePath = filePath.replace(/\\/g, '/');
9595

9696
// Workaround for https://github.com/angular/angular/issues/30060
97-
if (process.env['BAZEL_TARGET'].includes('test/bundling/core_all:size_test')) {
97+
if (process.env['BAZEL_TARGET']!.includes('test/bundling/core_all:size_test')) {
9898
return filePath.replace(/^(\.\.\/)+external/, 'external')
9999
.replace(/^(\.\.\/)+packages\/core\//, '@angular/core/')
100100
.replace(/^(\.\.\/){3}/, '@angular/core/');

tools/tsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"experimentalDecorators": true,
77
"module": "commonjs",
88
"moduleResolution": "node",
9+
"strict": true,
910
"outDir": "../dist/tools/",
1011
"noImplicitAny": true,
1112
"noFallthroughCasesInSwitch": true,

tools/tslint/requireInternalWithUnderscoreRule.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,6 @@ class TypedefWalker extends RuleWalker {
4747
}
4848
this.addFailure(this.createFailure(
4949
node.getStart(), node.getWidth(),
50-
`module-private member ${node.name.getText()} must be annotated @internal`));
50+
`module-private member ${node.name?.getText()} must be annotated @internal`));
5151
}
5252
}

tsconfig-tslint.json

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"compilerOptions": {
3+
"allowJs": true
4+
},
5+
"include": [
6+
"dev-infra/**/*",
7+
"packages/**/*",
8+
"modules/**/*",
9+
"tools/**/*",
10+
"scripts/**/*"
11+
]
12+
}

tslint.json

+15-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
{
22
"rulesDirectory": [
3-
"dist/tools/tslint",
3+
"tools/tslint",
4+
"dev-infra/tslint-rules",
45
"node_modules/vrsource-tslint-rules/rules",
56
"node_modules/tslint-eslint-rules/dist/rules",
67
"node_modules/tslint-no-toplevel-property-access/rules"
78
],
89
"rules": {
10+
// The first rule needs to be `ts-node-loader` which sets up `ts-node` within TSLint so
11+
// that rules written in TypeScript can be loaded without needing to be transpiled.
12+
"ts-node-loader": true,
13+
// Custom rules written in TypeScript.
14+
"require-internal-with-underscore": true,
15+
"no-implicit-override-abstract": true,
16+
917
"eofline": true,
1018
"file-header": [
1119
true,
@@ -26,7 +34,6 @@
2634
true,
2735
"object"
2836
],
29-
"require-internal-with-underscore": true,
3037
"no-toplevel-property-access": [
3138
true,
3239
"packages/animations/src/",
@@ -57,6 +64,12 @@
5764
]
5865
},
5966
"jsRules": {
67+
// The first rule needs to be `ts-node-loader` which sets up `ts-node` within TSLint so
68+
// that rules written in TypeScript can be loaded without needing to be transpiled.
69+
"ts-node-loader": true,
70+
// Custom rules written in TypeScript.
71+
"require-internal-with-underscore": true,
72+
6073
"eofline": true,
6174
"file-header": [
6275
true,
@@ -71,7 +84,6 @@
7184
],
7285
"no-duplicate-imports": true,
7386
"no-duplicate-variable": true,
74-
"require-internal-with-underscore": true,
7587
"semicolon": [
7688
true
7789
],

0 commit comments

Comments
 (0)