Skip to content

Commit f0677df

Browse files
authored
chore: enable unbound-method eslint rule (#165)
Unbound method calls using `this` are likely to have unintended effects. Here is an example with static methods, but the same thing applies to object methods: ```ts class Class { public static staticMethod() { this.otherStaticMethod() } public static otherStaticMethod() { } } // ✅ valid Class.staticMethod(); // ❌ boom const x = Class.staticMethod; x(); ``` When assigning a method to a variable, you need to take extra care and this linter rule is going to remind you. --- By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license
1 parent 7373ad7 commit f0677df

File tree

21 files changed

+27
-9
lines changed

21 files changed

+27
-9
lines changed

.eslintrc.json

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk/cdk-build-tools/.eslintrc.json

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk/cdk-cli-wrapper/.eslintrc.json

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk/cli-lib-alpha/.eslintrc.json

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk/cli-plugin-contract/.eslintrc.json

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk/cloud-assembly-schema/.eslintrc.json

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk/cloud-assembly-schema/lib/manifest.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ export class Manifest {
259259
* Ideally, we would start writing the `camelCased` and translate to how CloudFormation expects it when needed. But this requires nasty
260260
* backwards-compatibility code and it just doesn't seem to be worth the effort.
261261
*/
262-
private static patchStackTagsOnRead(manifest: assembly.AssemblyManifest) {
262+
private static patchStackTagsOnRead(this: void, manifest: assembly.AssemblyManifest) {
263263
return Manifest.replaceStackTags(manifest, (tags) =>
264264
tags.map((diskTag: any) => ({
265265
key: diskTag.Key,
@@ -273,6 +273,7 @@ export class Manifest {
273273
* should have dedicated properties preceding this (e.g `assumeRoleArn` and `assumeRoleExternalId`).
274274
*/
275275
private static validateAssumeRoleAdditionalOptions(
276+
this: void,
276277
instance: any,
277278
key: string,
278279
_schema: jsonschema.Schema,
@@ -301,7 +302,7 @@ export class Manifest {
301302
*
302303
* Translate stack tags metadata if it has the "right" casing.
303304
*/
304-
private static patchStackTagsOnWrite(manifest: assembly.AssemblyManifest) {
305+
private static patchStackTagsOnWrite(this: void, manifest: assembly.AssemblyManifest) {
305306
return Manifest.replaceStackTags(manifest, (tags) =>
306307
tags.map(
307308
(memTag) =>

packages/@aws-cdk/cloudformation-diff/.eslintrc.json

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk/node-bundle/.eslintrc.json

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk/toolkit-lib/.eslintrc.json

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk/toolkit-lib/lib/toolkit/toolkit.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ export class Toolkit extends CloudAssemblySourceBuilder implements AsyncDisposab
501501

502502
const stacksAndTheirAssetManifests = stacks.flatMap((stack) => [
503503
stack,
504-
...stack.dependencies.filter(cxapi.AssetManifestArtifact.isAssetManifestArtifact),
504+
...stack.dependencies.filter(x => cxapi.AssetManifestArtifact.isAssetManifestArtifact(x)),
505505
]);
506506
const workGraph = new WorkGraphBuilder({ ioHost, action }, prebuildAssets).build(stacksAndTheirAssetManifests);
507507

packages/@aws-cdk/toolkit-lib/test/_helpers/jest-bufferedconsole.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* eslint-disable import/no-extraneous-dependencies */
1+
/* eslint-disable import/no-extraneous-dependencies,@typescript-eslint/unbound-method */
22
/**
33
* A Jest environment that buffers outputs to `console.log()` and only shows it for failing tests.
44
*/

packages/@aws-cdk/user-input-gen/.eslintrc.json

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk/yarn-cling/.eslintrc.json

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/aws-cdk/.eslintrc.json

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/aws-cdk/lib/api/work-graph/work-graph-builder.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@ export class WorkGraphBuilder {
177177

178178
function stacksFromAssets(artifacts: cxapi.CloudArtifact[]) {
179179
const ret = new Map<cxapi.AssetManifestArtifact, cxapi.CloudFormationStackArtifact>();
180-
for (const stack of artifacts.filter(cxapi.CloudFormationStackArtifact.isCloudFormationStackArtifact)) {
181-
const assetArtifacts = stack.dependencies.filter(cxapi.AssetManifestArtifact.isAssetManifestArtifact);
180+
for (const stack of artifacts.filter(x => cxapi.CloudFormationStackArtifact.isCloudFormationStackArtifact(x))) {
181+
const assetArtifacts = stack.dependencies.filter((x) => cxapi.AssetManifestArtifact.isAssetManifestArtifact(x));
182182
for (const art of assetArtifacts) {
183183
ret.set(art, stack);
184184
}
@@ -188,5 +188,5 @@ function stacksFromAssets(artifacts: cxapi.CloudArtifact[]) {
188188
}
189189

190190
function onlyStacks(artifacts: cxapi.CloudArtifact[]) {
191-
return artifacts.filter(cxapi.CloudFormationStackArtifact.isCloudFormationStackArtifact);
191+
return artifacts.filter(x => cxapi.CloudFormationStackArtifact.isCloudFormationStackArtifact(x));
192192
}

packages/aws-cdk/lib/cli/cdk-toolkit.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ export class CdkToolkit {
581581

582582
const stacksAndTheirAssetManifests = stacks.flatMap((stack) => [
583583
stack,
584-
...stack.dependencies.filter(cxapi.AssetManifestArtifact.isAssetManifestArtifact),
584+
...stack.dependencies.filter(x => cxapi.AssetManifestArtifact.isAssetManifestArtifact(x)),
585585
]);
586586
const workGraph = new WorkGraphBuilder({
587587
ioHost: this.ioHost,

packages/aws-cdk/test/jest-bufferedconsole.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* eslint-disable import/no-extraneous-dependencies */
1+
/* eslint-disable import/no-extraneous-dependencies,@typescript-eslint/unbound-method */
22
/**
33
* A Jest environment that buffers outputs to `console.log()` and only shows it for failing tests.
44
*/

packages/cdk-assets/.eslintrc.json

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/cdk/.eslintrc.json

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

projenrc/eslint.ts

+3
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@ export const ESLINT_RULES = {
165165
],
166166
}],
167167

168+
// Unbound methods are a JavaScript footgun
169+
'@typescript-eslint/unbound-method': 'error',
170+
168171
// Overrides for plugin:jest/recommended
169172
'jest/expect-expect': 'off',
170173
'jest/no-conditional-expect': 'off',

0 commit comments

Comments
 (0)