Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: enable unbound-method eslint rule #33605

Merged
merged 5 commits into from
Feb 28, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as child_process from 'child_process';
import * as path from 'path';
import * as fs from 'fs-extra';
import { snapshotTestWorker } from '../../lib/workers/extract';
Expand Down Expand Up @@ -33,7 +32,6 @@ describe('Snapshot tests', () => {

test('has snapshot', () => {
// WHEN
jest.spyOn(child_process, 'spawnSync').mockResolvedValue;
const test = {
fileName: path.join(directory, 'xxxxx.test-with-snapshot.js'),
discoveryRoot: directory,
Expand All @@ -46,7 +44,6 @@ describe('Snapshot tests', () => {

test('failed snapshot', () => {
// WHEN
jest.spyOn(child_process, 'spawnSync').mockRejectedValue;
const test = {
fileName: path.join(directory, 'xxxxx.test-with-snapshot-assets-diff.js'),
discoveryRoot: directory,
Expand Down
2 changes: 1 addition & 1 deletion packages/aws-cdk-lib/aws-backup/lib/plan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ export class BackupPlan extends Resource implements IBackupPlan {
});
}

private planCopyActions(props: BackupPlanCopyActionProps): CfnBackupPlan.CopyActionResourceTypeProperty {
private planCopyActions(this: void, props: BackupPlanCopyActionProps): CfnBackupPlan.CopyActionResourceTypeProperty {
return {
destinationBackupVaultArn: props.destinationBackupVault.backupVaultArn,
lifecycle: (props.deleteAfter || props.moveToColdStorageAfter) && {
Expand Down
4 changes: 2 additions & 2 deletions packages/aws-cdk-lib/aws-cloudfront/lib/geo-restriction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class GeoRestriction {
* that you want to allow. Include one element for each country.
* See ISO 3166-1-alpha-2 code on the *International Organization for Standardization* website
*/
public static allowlist(...locations: string[]) {
public static allowlist(this: void, ...locations: string[]) {
return new GeoRestriction('whitelist', GeoRestriction.validateLocations(locations));
}

Expand All @@ -22,7 +22,7 @@ export class GeoRestriction {
* that you want to deny. Include one element for each country.
* See ISO 3166-1-alpha-2 code on the *International Organization for Standardization* website
*/
public static denylist(...locations: string[]) {
public static denylist(this: void, ...locations: string[]) {
return new GeoRestriction('blacklist', GeoRestriction.validateLocations(locations));
}

Expand Down
1 change: 1 addition & 0 deletions packages/aws-cdk-lib/aws-config/lib/rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@ export class CustomRule extends RuleNew {
}
const hash = createHash('sha256')
.update(JSON.stringify({
/* eslint-disable-next-line @typescript-eslint/unbound-method *//* REMOVEME: this is a latent bug */
fnName: props.lambdaFunction.functionName.toString,
accountId: Stack.of(this).resolve(this.env.account),
region: Stack.of(this).resolve(this.env.region),
Expand Down
12 changes: 6 additions & 6 deletions packages/aws-cdk-lib/aws-ec2/lib/cfn-init-elements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -655,42 +655,42 @@ export class InitPackage extends InitElement {
/**
* Install an RPM from an HTTP URL or a location on disk
*/
public static rpm(location: string, options: LocationPackageOptions = {}): InitPackage {
public static rpm(this: void, location: string, options: LocationPackageOptions = {}): InitPackage {
return new InitPackage('rpm', [location], options.key, options.serviceRestartHandles);
}

/**
* Install a package using Yum
*/
public static yum(packageName: string, options: NamedPackageOptions = {}): InitPackage {
public static yum(this: void, packageName: string, options: NamedPackageOptions = {}): InitPackage {
return new InitPackage('yum', options.version ?? [], packageName, options.serviceRestartHandles);
}

/**
* Install a package from RubyGems
*/
public static rubyGem(gemName: string, options: NamedPackageOptions = {}): InitPackage {
public static rubyGem(this: void, gemName: string, options: NamedPackageOptions = {}): InitPackage {
return new InitPackage('rubygems', options.version ?? [], gemName, options.serviceRestartHandles);
}

/**
* Install a package from PyPI
*/
public static python(packageName: string, options: NamedPackageOptions = {}): InitPackage {
public static python(this: void, packageName: string, options: NamedPackageOptions = {}): InitPackage {
return new InitPackage('python', options.version ?? [], packageName, options.serviceRestartHandles);
}

/**
* Install a package using APT
*/
public static apt(packageName: string, options: NamedPackageOptions = {}): InitPackage {
public static apt(this: void, packageName: string, options: NamedPackageOptions = {}): InitPackage {
return new InitPackage('apt', options.version ?? [], packageName, options.serviceRestartHandles);
}

/**
* Install an MSI package from an HTTP URL or a location on disk
*/
public static msi(location: string, options: LocationPackageOptions = {}): InitPackage {
public static msi(this: void, location: string, options: LocationPackageOptions = {}): InitPackage {
// The MSI package version must be a string, not an array.
return new class extends InitPackage {
protected renderPackageVersions() { return location; }
Expand Down
6 changes: 3 additions & 3 deletions packages/aws-cdk-lib/aws-ec2/test/ip-addresses.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ describe('Cidr vpc allocation', () => {

test('Default Cidr returns ipv4IpamPoolId as undefined', () => {
const ipAddresses = IpAddresses.cidr('10.0.0.0/16');
expect(ipAddresses.allocateVpcCidr().ipv4IpamPoolId).toBeUndefined;
expect(ipAddresses.allocateVpcCidr().ipv4IpamPoolId).toBeUndefined();
});

test('Default Cidr returns ipv4NetmaskLength as undefined', () => {
const ipAddresses = IpAddresses.cidr('10.0.0.0/16');
expect(ipAddresses.allocateVpcCidr().ipv4NetmaskLength).toBeUndefined;
expect(ipAddresses.allocateVpcCidr().ipv4NetmaskLength).toBeUndefined();
});
});

Expand Down Expand Up @@ -102,7 +102,7 @@ describe('AwsIpam vpc allocation', () => {

test('AwsIpam returns cidrBlock as undefined', () => {
const ipAddresses = IpAddresses.awsIpamAllocation(awsIpamProps);
expect(ipAddresses.allocateVpcCidr().cidrBlock).toBeUndefined;
expect(ipAddresses.allocateVpcCidr().cidrBlock).toBeUndefined();
});

test('AwsIpam returns the correct vpc ipv4IpamPoolId', () => {
Expand Down
1 change: 1 addition & 0 deletions packages/aws-cdk-lib/aws-ec2/test/vpc.from-lookup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ interface MockVpcContextResponse {
function mockVpcContextProviderWith(
response: MockVpcContextResponse,
paramValidator?: (options: cxschema.VpcContextQuery) => void) {
// eslint-disable-next-line @typescript-eslint/unbound-method
const previous = ContextProvider.getValue;
ContextProvider.getValue = (_scope: Construct, options: GetContextValueOptions) => {
// do some basic sanity checks
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ describe('ApplicationLoadBalancedFargateService', () => {
// THEN
expect(() => {
service.internalDesiredCount;
}).toBeTruthy;
}).toBeTruthy();
});

test('multiple capacity provider strategies are set', () => {
Expand Down
1 change: 1 addition & 0 deletions packages/aws-cdk-lib/aws-ecs/test/cluster.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/unbound-method */
import { testDeprecated } from '@aws-cdk/cdk-build-tools';
import { Annotations, Match, Template } from '../../assertions';
import * as autoscaling from '../../aws-autoscaling';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ describe('fargate task definition', () => {
// THEN
expect(() => {
taskDefinition.ephemeralStorageGiB;
}).toBeTruthy;
}).toBeTruthy();
});

test('runtime testing for windows container', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/aws-cdk-lib/aws-eks/lib/managed-nodegroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ function getPossibleAmiTypes(instanceTypes: InstanceType[]): NodegroupAmiType[]
const architectures: Set<AmiArchitecture> = new Set(instanceTypes.map(typeToArch));

if (architectures.size === 0) { // protective code, the current implementation will never result in this.
throw new Error(`Cannot determine any ami type compatible with instance types: ${instanceTypes.map(i => i.toString).join(', ')}`);
throw new Error(`Cannot determine any ami type compatible with instance types: ${instanceTypes.map(i => i.toString()).join(', ')}`);
}

if (architectures.size > 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ export class ListenerCertificate implements IListenerCertificate {
/**
* Use an ACM certificate as a listener certificate
*/
public static fromCertificateManager(acmCertificate: acm.ICertificate) {
public static fromCertificateManager(this: void, acmCertificate: acm.ICertificate) {
return new ListenerCertificate(acmCertificate.certificateArn);
}

/**
* Use any certificate, identified by its ARN, as a listener certificate
*/
public static fromArn(certificateArn: string) {
public static fromArn(this: void, certificateArn: string) {
return new ListenerCertificate(certificateArn);
}

Expand Down
4 changes: 2 additions & 2 deletions packages/aws-cdk-lib/aws-iam/lib/principals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,14 @@ export class ComparablePrincipal {
/**
* Whether or not the given principal is a comparable principal
*/
public static isComparablePrincipal(x: IPrincipal): x is IComparablePrincipal {
public static isComparablePrincipal(this: void, x: IPrincipal): x is IComparablePrincipal {
return 'dedupeString' in x;
}

/**
* Return the dedupeString of the given principal, if available
*/
public static dedupeStringFor(x: IPrincipal): string | undefined {
public static dedupeStringFor(this: void, x: IPrincipal): string | undefined {
return ComparablePrincipal.isComparablePrincipal(x) ? x.dedupeString() : undefined;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,136 +9,136 @@ import { KinesisMetrics as CannedMetrics } from './kinesis-canned-metrics.genera
* Stream Metrics reference: https://docs.aws.amazon.com/streams/latest/dev/monitoring-with-cloudwatch.html
*/
export class KinesisMetrics {
public static getRecordsBytesAverage(dimensions: { StreamName: string }) {
public static getRecordsBytesAverage(this: void, dimensions: { StreamName: string }) {
return {
namespace: 'AWS/Kinesis',
metricName: 'GetRecords.Bytes',
dimensionsMap: dimensions,
statistic: 'Average',
};
}
public static getRecordsSuccessAverage(dimensions: { StreamName: string }) {
public static getRecordsSuccessAverage(this: void, dimensions: { StreamName: string }) {
return {
namespace: 'AWS/Kinesis',
metricName: 'GetRecords.Success',
dimensionsMap: dimensions,
statistic: 'Average',
};
}
public static getRecordsRecordsAverage(dimensions: { StreamName: string }) {
public static getRecordsRecordsAverage(this: void, dimensions: { StreamName: string }) {
return {
namespace: 'AWS/Kinesis',
metricName: 'GetRecords.Records',
dimensionsMap: dimensions,
statistic: 'Average',
};
}
public static getRecordsLatencyAverage(dimensions: { StreamName: string }) {
public static getRecordsLatencyAverage(this: void, dimensions: { StreamName: string }) {
return {
namespace: 'AWS/Kinesis',
metricName: 'GetRecords.Latency',
dimensionsMap: dimensions,
statistic: 'Average',
};
}
public static putRecordBytesAverage(dimensions: { StreamName: string }) {
public static putRecordBytesAverage(this: void, dimensions: { StreamName: string }) {
return {
namespace: 'AWS/Kinesis',
metricName: 'PutRecord.Bytes',
dimensionsMap: dimensions,
statistic: 'Average',
};
}
public static putRecordLatencyAverage(dimensions: { StreamName: string }) {
public static putRecordLatencyAverage(this: void, dimensions: { StreamName: string }) {
return {
namespace: 'AWS/Kinesis',
metricName: 'PutRecord.Latency',
dimensionsMap: dimensions,
statistic: 'Average',
};
}
public static getRecordsIteratorAgeMillisecondsMaximum(dimensions: { StreamName: string }) {
public static getRecordsIteratorAgeMillisecondsMaximum(this: void, dimensions: { StreamName: string }) {
return CannedMetrics.getRecordsIteratorAgeMillisecondsMaximum(dimensions);
}
public static putRecordSuccessAverage(dimensions: { StreamName: string }) {
public static putRecordSuccessAverage(this: void, dimensions: { StreamName: string }) {
return {
...CannedMetrics.putRecordSuccessSum(dimensions),
statistic: 'Average',
};
}
public static putRecordsBytesAverage(dimensions: { StreamName: string }) {
public static putRecordsBytesAverage(this: void, dimensions: { StreamName: string }) {
return {
...CannedMetrics.putRecordsBytesSum(dimensions),
statistic: 'Average',
};
}
public static putRecordsLatencyAverage(dimensions: { StreamName: string }) {
public static putRecordsLatencyAverage(this: void, dimensions: { StreamName: string }) {
return {
namespace: 'AWS/Kinesis',
metricName: 'PutRecords.Latency',
dimensionsMap: dimensions,
statistic: 'Average',
};
}
public static putRecordsSuccessAverage(dimensions: { StreamName: string }) {
public static putRecordsSuccessAverage(this: void, dimensions: { StreamName: string }) {
return {
namespace: 'AWS/Kinesis',
metricName: 'PutRecords.Success',
dimensionsMap: dimensions,
statistic: 'Average',
};
}
public static putRecordsTotalRecordsAverage(dimensions: { StreamName: string }) {
public static putRecordsTotalRecordsAverage(this: void, dimensions: { StreamName: string }) {
return {
namespace: 'AWS/Kinesis',
metricName: 'PutRecords.TotalRecords',
dimensionsMap: dimensions,
statistic: 'Average',
};
}
public static putRecordsSuccessfulRecordsAverage(dimensions: { StreamName: string }) {
public static putRecordsSuccessfulRecordsAverage(this: void, dimensions: { StreamName: string }) {
return {
namespace: 'AWS/Kinesis',
metricName: 'PutRecords.SuccessfulRecords',
dimensionsMap: dimensions,
statistic: 'Average',
};
}
public static putRecordsFailedRecordsAverage(dimensions: { StreamName: string }) {
public static putRecordsFailedRecordsAverage(this: void, dimensions: { StreamName: string }) {
return {
namespace: 'AWS/Kinesis',
metricName: 'PutRecords.FailedRecords',
dimensionsMap: dimensions,
statistic: 'Average',
};
}
public static putRecordsThrottledRecordsAverage(dimensions: { StreamName: string }) {
public static putRecordsThrottledRecordsAverage(this: void, dimensions: { StreamName: string }) {
return {
namespace: 'AWS/Kinesis',
metricName: 'PutRecords.ThrottledRecords',
dimensionsMap: dimensions,
statistic: 'Average',
};
}
public static incomingBytesAverage(dimensions: { StreamName: string }) {
public static incomingBytesAverage(this: void, dimensions: { StreamName: string }) {
return {
...CannedMetrics.incomingBytesSum(dimensions),
statistic: 'Average',
};
}
public static incomingRecordsAverage(dimensions: { StreamName: string }) {
public static incomingRecordsAverage(this: void, dimensions: { StreamName: string }) {
return {
...CannedMetrics.incomingRecordsSum(dimensions),
statistic: 'Average',
};
}
public static readProvisionedThroughputExceededAverage(dimensions: { StreamName: string }) {
public static readProvisionedThroughputExceededAverage(this: void, dimensions: { StreamName: string }) {
return {
...CannedMetrics.readProvisionedThroughputExceededSum(dimensions),
statistic: 'Average',
};
}
public static writeProvisionedThroughputExceededAverage(dimensions: { StreamName: string }) {
public static writeProvisionedThroughputExceededAverage(this: void, dimensions: { StreamName: string }) {
return {
...CannedMetrics.writeProvisionedThroughputExceededSum(dimensions),
statistic: 'Average',
Expand Down
2 changes: 1 addition & 1 deletion packages/aws-cdk-lib/aws-kinesis/lib/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ abstract class StreamBase extends Resource implements IStream {
node: this.node,
stack: this.stack,
env: this.env,
applyRemovalPolicy: this.applyRemovalPolicy,
applyRemovalPolicy: x => this.applyRemovalPolicy(x),
},
});
}
Expand Down
1 change: 1 addition & 0 deletions packages/aws-cdk-lib/aws-kms/test/key.from-lookup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ interface MockKeyContextResponse {
function mockKeyContextProviderWith(
response: MockKeyContextResponse,
paramValidator?: (options: cxschema.KeyContextQuery) => void) {
// eslint-disable-next-line @typescript-eslint/unbound-method
const previous = ContextProvider.getValue;
ContextProvider.getValue = (_scope: Construct, options: GetContextValueOptions) => {
// do some basic sanity checks
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/unbound-method */
import * as child_process from 'child_process';
import * as fs from 'fs';
import * as os from 'os';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/unbound-method */
import * as child_process from 'child_process';
import { bockfs } from '@aws-cdk/cdk-build-tools';
import { Annotations, Template, Match } from '../../assertions';
Expand Down
2 changes: 1 addition & 1 deletion packages/aws-cdk-lib/aws-lambda/lib/function-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ export abstract class FunctionBase extends Resource implements IFunction, ec2.IC
node: this.node,
stack: this.stack,
env: this.env,
applyRemovalPolicy: this.applyRemovalPolicy,
applyRemovalPolicy: x => this.applyRemovalPolicy(x),
},
});

Expand Down
Loading