diff --git a/packages/@aws-cdk/assert/lib/assertions/have-resource.ts b/packages/@aws-cdk/assert/lib/assertions/have-resource.ts index 3e44013188b2c..5a977d8252fd4 100644 --- a/packages/@aws-cdk/assert/lib/assertions/have-resource.ts +++ b/packages/@aws-cdk/assert/lib/assertions/have-resource.ts @@ -59,7 +59,7 @@ export class HaveResourceAssertion extends JestFriendlyAssertion properties === undefined ? anything() : allowValueExtension ? deepObjectLike(properties) : objectLike(properties); - this.part = part !== undefined ? part : ResourcePart.Properties; + this.part = part ?? ResourcePart.Properties; } public assertUsing(inspector: StackInspector): boolean { diff --git a/packages/@aws-cdk/aws-amplify/lib/app.ts b/packages/@aws-cdk/aws-amplify/lib/app.ts index 8e7217a59cc58..bf1d5bc3d5e89 100644 --- a/packages/@aws-cdk/aws-amplify/lib/app.ts +++ b/packages/@aws-cdk/aws-amplify/lib/app.ts @@ -218,9 +218,9 @@ export class App extends Resource implements IApp, iam.IGrantable { basicAuthConfig: props.autoBranchCreation.basicAuth && props.autoBranchCreation.basicAuth.bind(this, 'BranchBasicAuth'), buildSpec: props.autoBranchCreation.buildSpec && props.autoBranchCreation.buildSpec.toBuildSpec(), enableAutoBranchCreation: true, - enableAutoBuild: props.autoBranchCreation.autoBuild === undefined ? true : props.autoBranchCreation.autoBuild, + enableAutoBuild: props.autoBranchCreation.autoBuild ?? true, environmentVariables: Lazy.any({ produce: () => renderEnvironmentVariables(this.autoBranchEnvironmentVariables ) }, { omitEmptyArray: true }), // eslint-disable-line max-len - enablePullRequestPreview: props.autoBranchCreation.pullRequestPreview === undefined ? true : props.autoBranchCreation.pullRequestPreview, + enablePullRequestPreview: props.autoBranchCreation.pullRequestPreview ?? true, pullRequestEnvironmentName: props.autoBranchCreation.pullRequestEnvironmentName, stage: props.autoBranchCreation.stage, }, diff --git a/packages/@aws-cdk/aws-amplify/lib/branch.ts b/packages/@aws-cdk/aws-amplify/lib/branch.ts index e26fe6c4d46a2..210f27d4831e2 100644 --- a/packages/@aws-cdk/aws-amplify/lib/branch.ts +++ b/packages/@aws-cdk/aws-amplify/lib/branch.ts @@ -139,8 +139,8 @@ export class Branch extends Resource implements IBranch { branchName, buildSpec: props.buildSpec && props.buildSpec.toBuildSpec(), description: props.description, - enableAutoBuild: props.autoBuild === undefined ? true : props.autoBuild, - enablePullRequestPreview: props.pullRequestPreview === undefined ? true : props.pullRequestPreview, + enableAutoBuild: props.autoBuild ?? true, + enablePullRequestPreview: props.pullRequestPreview ?? true, environmentVariables: Lazy.any({ produce: () => renderEnvironmentVariables(this.environmentVariables) }, { omitEmptyArray: true }), pullRequestEnvironmentName: props.pullRequestEnvironmentName, stage: props.stage, diff --git a/packages/@aws-cdk/aws-amplify/lib/domain.ts b/packages/@aws-cdk/aws-amplify/lib/domain.ts index b657ebdefb247..bf6ba7afe8017 100644 --- a/packages/@aws-cdk/aws-amplify/lib/domain.ts +++ b/packages/@aws-cdk/aws-amplify/lib/domain.ts @@ -147,7 +147,7 @@ export class Domain extends Resource { private renderSubDomainSettings() { return this.subDomains.map(s => ({ branchName: s.branch.branchName, - prefix: s.prefix === undefined ? s.branch.branchName : s.prefix, + prefix: s.prefix ?? s.branch.branchName, })); } } diff --git a/packages/@aws-cdk/aws-apigateway/lib/integrations/http.ts b/packages/@aws-cdk/aws-apigateway/lib/integrations/http.ts index fac5bb7cc6800..65f0657e19817 100644 --- a/packages/@aws-cdk/aws-apigateway/lib/integrations/http.ts +++ b/packages/@aws-cdk/aws-apigateway/lib/integrations/http.ts @@ -38,7 +38,7 @@ export interface HttpIntegrationProps { */ export class HttpIntegration extends Integration { constructor(url: string, props: HttpIntegrationProps = { }) { - const proxy = props.proxy !== undefined ? props.proxy : true; + const proxy = props.proxy ?? true; const method = props.httpMethod || 'GET'; super({ type: proxy ? IntegrationType.HTTP_PROXY : IntegrationType.HTTP, diff --git a/packages/@aws-cdk/aws-apigateway/lib/integrations/lambda.ts b/packages/@aws-cdk/aws-apigateway/lib/integrations/lambda.ts index 399484510f343..97772fe7eddb5 100644 --- a/packages/@aws-cdk/aws-apigateway/lib/integrations/lambda.ts +++ b/packages/@aws-cdk/aws-apigateway/lib/integrations/lambda.ts @@ -41,7 +41,7 @@ export class LambdaIntegration extends AwsIntegration { private readonly enableTest: boolean; constructor(handler: lambda.IFunction, options: LambdaIntegrationOptions = { }) { - const proxy = options.proxy === undefined ? true : options.proxy; + const proxy = options.proxy ?? true; super({ proxy, @@ -51,7 +51,7 @@ export class LambdaIntegration extends AwsIntegration { }); this.handler = handler; - this.enableTest = options.allowTestInvoke === undefined ? true : options.allowTestInvoke; + this.enableTest = options.allowTestInvoke ?? true; } public bind(method: Method): IntegrationConfig { diff --git a/packages/@aws-cdk/aws-apigateway/lib/resource.ts b/packages/@aws-cdk/aws-apigateway/lib/resource.ts index 33ec6f1d5f7fd..49d0bf0356d80 100644 --- a/packages/@aws-cdk/aws-apigateway/lib/resource.ts +++ b/packages/@aws-cdk/aws-apigateway/lib/resource.ts @@ -276,7 +276,7 @@ export abstract class ResourceBase extends ResourceConstruct implements IResourc // // statusCode - const statusCode = options.statusCode !== undefined ? options.statusCode : 204; + const statusCode = options.statusCode ?? 204; // // prepare responseParams @@ -522,7 +522,7 @@ export class ProxyResource extends Resource { defaultMethodOptions: props.defaultMethodOptions, }); - const anyMethod = props.anyMethod !== undefined ? props.anyMethod : true; + const anyMethod = props.anyMethod ?? true; if (anyMethod) { this.anyMethod = this.addMethod('ANY'); } diff --git a/packages/@aws-cdk/aws-apigateway/lib/restapi.ts b/packages/@aws-cdk/aws-apigateway/lib/restapi.ts index 0911c92dda94b..32c400c52d23e 100644 --- a/packages/@aws-cdk/aws-apigateway/lib/restapi.ts +++ b/packages/@aws-cdk/aws-apigateway/lib/restapi.ts @@ -504,7 +504,7 @@ export abstract class RestApiBase extends Resource implements IRestApi { } protected configureDeployment(props: RestApiOptions) { - const deploy = props.deploy === undefined ? true : props.deploy; + const deploy = props.deploy ?? true; if (deploy) { this._latestDeployment = new Deployment(this, 'Deployment', { @@ -593,7 +593,7 @@ export class SpecRestApi extends RestApiBase { name: this.restApiName, policy: props.policy, failOnWarnings: props.failOnWarnings, - body: apiDefConfig.inlineDefinition ? apiDefConfig.inlineDefinition : undefined, + body: apiDefConfig.inlineDefinition ?? undefined, bodyS3Location: apiDefConfig.inlineDefinition ? undefined : apiDefConfig.s3Location, endpointConfiguration: this._configureEndpoints(props), parameters: props.parameters, @@ -608,7 +608,7 @@ export class SpecRestApi extends RestApiBase { this.addDomainName('CustomDomain', props.domainName); } - const cloudWatchRole = props.cloudWatchRole !== undefined ? props.cloudWatchRole : true; + const cloudWatchRole = props.cloudWatchRole ?? true; if (cloudWatchRole) { this.configureCloudWatchRole(resource); } @@ -700,13 +700,13 @@ export class RestApi extends RestApiBase { binaryMediaTypes: props.binaryMediaTypes, endpointConfiguration: this._configureEndpoints(props), apiKeySourceType: props.apiKeySourceType, - cloneFrom: props.cloneFrom ? props.cloneFrom.restApiId : undefined, + cloneFrom: props.cloneFrom?.restApiId, parameters: props.parameters, }); this.node.defaultChild = resource; this.restApiId = resource.ref; - const cloudWatchRole = props.cloudWatchRole !== undefined ? props.cloudWatchRole : true; + const cloudWatchRole = props.cloudWatchRole ?? true; if (cloudWatchRole) { this.configureCloudWatchRole(resource); } diff --git a/packages/@aws-cdk/aws-applicationautoscaling/lib/base-scalable-attribute.ts b/packages/@aws-cdk/aws-applicationautoscaling/lib/base-scalable-attribute.ts index 762da275c33a5..95d2a19c8a17d 100644 --- a/packages/@aws-cdk/aws-applicationautoscaling/lib/base-scalable-attribute.ts +++ b/packages/@aws-cdk/aws-applicationautoscaling/lib/base-scalable-attribute.ts @@ -58,7 +58,7 @@ export abstract class BaseScalableAttribute extends CoreConstruct { scalableDimension: this.props.dimension, resourceId: this.props.resourceId, role: this.props.role, - minCapacity: props.minCapacity !== undefined ? props.minCapacity : 1, + minCapacity: props.minCapacity ?? 1, maxCapacity: props.maxCapacity, }); } diff --git a/packages/@aws-cdk/aws-autoscaling-common/lib/interval-utils.ts b/packages/@aws-cdk/aws-autoscaling-common/lib/interval-utils.ts index 39a05beb1e70e..246bfc018507b 100644 --- a/packages/@aws-cdk/aws-autoscaling-common/lib/interval-utils.ts +++ b/packages/@aws-cdk/aws-autoscaling-common/lib/interval-utils.ts @@ -43,7 +43,7 @@ function orderAndCompleteIntervals(intervals: ScalingInterval[]): CompleteScalin intervals = intervals.map(x => ({ ...x })); // Sort by whatever number we have for each interval - intervals.sort(comparatorFromKey((x: ScalingInterval) => x.lower !== undefined ? x.lower : x.upper)); + intervals.sort(comparatorFromKey((x: ScalingInterval) => x.lower ?? x.upper)); // Propagate boundaries until no more change while (propagateBounds(intervals)) { /* Repeat */ } diff --git a/packages/@aws-cdk/aws-autoscaling/lib/auto-scaling-group.ts b/packages/@aws-cdk/aws-autoscaling/lib/auto-scaling-group.ts index 0d5dd3f147235..4b14a4ea710cb 100644 --- a/packages/@aws-cdk/aws-autoscaling/lib/auto-scaling-group.ts +++ b/packages/@aws-cdk/aws-autoscaling/lib/auto-scaling-group.ts @@ -957,9 +957,8 @@ export class AutoScalingGroup extends AutoScalingGroupBase implements // desiredCapacity just reflects what the user has supplied. const desiredCapacity = props.desiredCapacity; - const minCapacity = props.minCapacity !== undefined ? props.minCapacity : 1; - const maxCapacity = props.maxCapacity !== undefined ? props.maxCapacity : - desiredCapacity !== undefined ? desiredCapacity : Math.max(minCapacity, 1); + const minCapacity = props.minCapacity ?? 1; + const maxCapacity = props.maxCapacity ?? desiredCapacity ?? Math.max(minCapacity, 1); withResolved(minCapacity, maxCapacity, (min, max) => { if (min > max) { @@ -1009,7 +1008,7 @@ export class AutoScalingGroup extends AutoScalingGroupBase implements const { subnetIds, hasPublic } = props.vpc.selectSubnets(props.vpcSubnets); const asgProps: CfnAutoScalingGroupProps = { autoScalingGroupName: this.physicalName, - cooldown: props.cooldown !== undefined ? props.cooldown.toSeconds().toString() : undefined, + cooldown: props.cooldown?.toSeconds().toString(), minSize: Tokenization.stringifyNumber(minCapacity), maxSize: Tokenization.stringifyNumber(maxCapacity), desiredCapacity: desiredCapacity !== undefined ? Tokenization.stringifyNumber(desiredCapacity) : undefined, @@ -1509,7 +1508,7 @@ enum HealthCheckType { * Render the rolling update configuration into the appropriate object */ function renderRollingUpdateConfig(config: RollingUpdateConfiguration = {}): CfnAutoScalingRollingUpdate { - const waitOnResourceSignals = config.minSuccessfulInstancesPercent !== undefined ? true : false; + const waitOnResourceSignals = config.minSuccessfulInstancesPercent !== undefined; const pauseTime = config.pauseTime || (waitOnResourceSignals ? Duration.minutes(5) : Duration.seconds(0)); return { diff --git a/packages/@aws-cdk/aws-batch/lib/compute-environment.ts b/packages/@aws-cdk/aws-batch/lib/compute-environment.ts index 96c356ac13d50..18a2d1a446325 100644 --- a/packages/@aws-cdk/aws-batch/lib/compute-environment.ts +++ b/packages/@aws-cdk/aws-batch/lib/compute-environment.ts @@ -374,7 +374,7 @@ export class ComputeEnvironment extends Resource implements IComputeEnvironment minvCpus: props.computeResources.minvCpus || 0, placementGroup: props.computeResources.placementGroup, securityGroupIds: this.buildSecurityGroupIds(props.computeResources.vpc, props.computeResources.securityGroups), - spotIamFleetRole: spotFleetRole ? spotFleetRole.roleArn : undefined, + spotIamFleetRole: spotFleetRole?.roleArn, subnets: props.computeResources.vpc.selectSubnets(props.computeResources.vpcSubnets).subnetIds, tags: props.computeResources.computeResourcesTags, type: props.computeResources.type || ComputeResourceType.ON_DEMAND, @@ -384,9 +384,8 @@ export class ComputeEnvironment extends Resource implements IComputeEnvironment const computeEnvironment = new CfnComputeEnvironment(this, 'Resource', { computeEnvironmentName: this.physicalName, computeResources, - serviceRole: props.serviceRole - ? props.serviceRole.roleArn - : new iam.Role(this, 'Resource-Service-Instance-Role', { + serviceRole: props.serviceRole?.roleArn + ?? new iam.Role(this, 'Resource-Service-Instance-Role', { managedPolicies: [ iam.ManagedPolicy.fromAwsManagedPolicyName('service-role/AWSBatchServiceRole'), ], @@ -409,7 +408,7 @@ export class ComputeEnvironment extends Resource implements IComputeEnvironment } private isManaged(props: ComputeEnvironmentProps): boolean { - return props.managed === undefined ? true : props.managed; + return props.managed ?? true; } /** diff --git a/packages/@aws-cdk/aws-cloudformation/lib/nested-stack.ts b/packages/@aws-cdk/aws-cloudformation/lib/nested-stack.ts index 57268c5291bb9..c72d94598ecfc 100644 --- a/packages/@aws-cdk/aws-cloudformation/lib/nested-stack.ts +++ b/packages/@aws-cdk/aws-cloudformation/lib/nested-stack.ts @@ -71,7 +71,7 @@ export class NestedStack extends core.NestedStack { super(scope, id, { parameters: props.parameters, timeout: props.timeout, - notificationArns: props.notifications ? props.notifications.map(n => n.topicArn) : undefined, + notificationArns: props.notifications?.map(n => n.topicArn), }); } } diff --git a/packages/@aws-cdk/aws-cloudformation/test/integ.nested-stack.ts b/packages/@aws-cdk/aws-cloudformation/test/integ.nested-stack.ts index 9bb2ba7e5f852..b6357115f7667 100644 --- a/packages/@aws-cdk/aws-cloudformation/test/integ.nested-stack.ts +++ b/packages/@aws-cdk/aws-cloudformation/test/integ.nested-stack.ts @@ -46,7 +46,7 @@ class MyNestedStack extends cfn.NestedStack { code: lambda.Code.inline('console.error("hi")'), handler: 'index.handler', environment: { - TOPIC_ARN: props.siblingTopic ? props.siblingTopic.topicArn : '', + TOPIC_ARN: props.siblingTopic?.topicArn ?? '', QUEUE_URL: props.subscriber.queueUrl, // nested stack references a resource in the parent }, }); diff --git a/packages/@aws-cdk/aws-cloudfront/lib/web-distribution.ts b/packages/@aws-cdk/aws-cloudfront/lib/web-distribution.ts index ae3cbae6051d3..f191813dada2b 100644 --- a/packages/@aws-cdk/aws-cloudfront/lib/web-distribution.ts +++ b/packages/@aws-cdk/aws-cloudfront/lib/web-distribution.ts @@ -771,10 +771,10 @@ export class CloudFrontWebDistribution extends cdk.Resource implements IDistribu let distributionConfig: CfnDistribution.DistributionConfigProperty = { comment: props.comment, enabled: true, - defaultRootObject: props.defaultRootObject !== undefined ? props.defaultRootObject : 'index.html', + defaultRootObject: props.defaultRootObject ?? 'index.html', httpVersion: props.httpVersion || HttpVersion.HTTP2, priceClass: props.priceClass || PriceClass.PRICE_CLASS_100, - ipv6Enabled: (props.enableIpV6 !== undefined) ? props.enableIpV6 : true, + ipv6Enabled: props.enableIpV6 ?? true, // eslint-disable-next-line max-len customErrorResponses: props.errorConfigurations, // TODO: validation : https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-cloudfront-distribution-customerrorresponse.html#cfn-cloudfront-distribution-customerrorresponse-errorcachingminttl webAclId: props.webACLId, diff --git a/packages/@aws-cdk/aws-cloudwatch/lib/graph.ts b/packages/@aws-cdk/aws-cloudwatch/lib/graph.ts index f232b5d27edf5..98f8980db4f4b 100644 --- a/packages/@aws-cdk/aws-cloudwatch/lib/graph.ts +++ b/packages/@aws-cdk/aws-cloudwatch/lib/graph.ts @@ -114,7 +114,7 @@ export class AlarmWidget extends ConcreteWidget { alarms: [this.props.alarm.alarmArn], }, yAxis: { - left: this.props.leftYAxis !== undefined ? this.props.leftYAxis : undefined, + left: this.props.leftYAxis ?? undefined, }, }, }]; @@ -271,8 +271,8 @@ export class GraphWidget extends ConcreteWidget { metrics: metrics.length > 0 ? metrics : undefined, annotations: horizontalAnnotations.length > 0 ? { horizontal: horizontalAnnotations } : undefined, yAxis: { - left: this.props.leftYAxis !== undefined ? this.props.leftYAxis : undefined, - right: this.props.rightYAxis !== undefined ? this.props.rightYAxis : undefined, + left: this.props.leftYAxis ?? undefined, + right: this.props.rightYAxis ?? undefined, }, legend: this.props.legendPosition !== undefined ? { position: this.props.legendPosition } : undefined, liveData: this.props.liveData, diff --git a/packages/@aws-cdk/aws-codebuild/lib/source.ts b/packages/@aws-cdk/aws-codebuild/lib/source.ts index 7706328a92bc7..19161ef9b6172 100644 --- a/packages/@aws-cdk/aws-codebuild/lib/source.ts +++ b/packages/@aws-cdk/aws-codebuild/lib/source.ts @@ -515,14 +515,14 @@ abstract class ThirdPartyGitSource extends GitSource { super(props); this.webhook = props.webhook; - this.reportBuildStatus = props.reportBuildStatus === undefined ? true : props.reportBuildStatus; + this.reportBuildStatus = props.reportBuildStatus ?? true; this.webhookFilters = props.webhookFilters || []; this.webhookTriggersBatchBuild = props.webhookTriggersBatchBuild; } public bind(_scope: CoreConstruct, project: IProject): SourceConfig { const anyFilterGroupsProvided = this.webhookFilters.length > 0; - const webhook = this.webhook === undefined ? (anyFilterGroupsProvided ? true : undefined) : this.webhook; + const webhook = this.webhook ?? (anyFilterGroupsProvided ? true : undefined); if (!webhook && anyFilterGroupsProvided) { throw new Error('`webhookFilters` cannot be used when `webhook` is `false`'); diff --git a/packages/@aws-cdk/aws-codedeploy/lib/lambda/custom-deployment-config.ts b/packages/@aws-cdk/aws-codedeploy/lib/lambda/custom-deployment-config.ts index 20822a0d2356b..55077fe93f273 100644 --- a/packages/@aws-cdk/aws-codedeploy/lib/lambda/custom-deployment-config.ts +++ b/packages/@aws-cdk/aws-codedeploy/lib/lambda/custom-deployment-config.ts @@ -99,9 +99,8 @@ export class CustomLambdaDeploymentConfig extends Resource implements ILambdaDep // Generates the name of the deployment config. It's also what you'll see in the AWS console // The name of the config is .LambdaPercentMinutes // Unless the user provides an explicit name - this.deploymentConfigName = props.deploymentConfigName !== undefined - ? props.deploymentConfigName - : `${Names.uniqueId(this)}.Lambda${props.type}${props.percentage}Percent${props.type === CustomLambdaDeploymentConfigType.LINEAR + this.deploymentConfigName = props.deploymentConfigName + ?? `${Names.uniqueId(this)}.Lambda${props.type}${props.percentage}Percent${props.type === CustomLambdaDeploymentConfigType.LINEAR ? 'Every' : ''}${props.interval.toMinutes()}Minutes`; this.deploymentConfigArn = arnForDeploymentConfig(this.deploymentConfigName); diff --git a/packages/@aws-cdk/aws-codedeploy/lib/server/deployment-group.ts b/packages/@aws-cdk/aws-codedeploy/lib/server/deployment-group.ts index 0864d603d2e28..e1108acb5205d 100644 --- a/packages/@aws-cdk/aws-codedeploy/lib/server/deployment-group.ts +++ b/packages/@aws-cdk/aws-codedeploy/lib/server/deployment-group.ts @@ -277,7 +277,7 @@ export class ServerDeploymentGroup extends ServerDeploymentGroupBase { }); this._autoScalingGroups = props.autoScalingGroups || []; - this.installAgent = props.installAgent === undefined ? true : props.installAgent; + this.installAgent = props.installAgent ?? true; this.codeDeployBucket = s3.Bucket.fromBucketName(this, 'Bucket', `aws-codedeploy-${cdk.Stack.of(this).region}`); for (const asg of this._autoScalingGroups) { this.addCodeDeployAgentInstallUserData(asg); diff --git a/packages/@aws-cdk/aws-codepipeline-actions/lib/custom-action-registration.ts b/packages/@aws-cdk/aws-codepipeline-actions/lib/custom-action-registration.ts index 41e34ac8a0b5d..dad9e84a47094 100644 --- a/packages/@aws-cdk/aws-codepipeline-actions/lib/custom-action-registration.ts +++ b/packages/@aws-cdk/aws-codepipeline-actions/lib/custom-action-registration.ts @@ -132,7 +132,7 @@ export class CustomActionRegistration extends Construct { entityUrlTemplate: props.entityUrl, executionUrlTemplate: props.executionUrl, }, - configurationProperties: props.actionProperties === undefined ? undefined : props.actionProperties.map((ap) => { + configurationProperties: props.actionProperties?.map((ap) => { return { key: ap.key || false, secret: ap.secret || false, diff --git a/packages/@aws-cdk/aws-codepipeline/lib/private/full-action-descriptor.ts b/packages/@aws-cdk/aws-codepipeline/lib/private/full-action-descriptor.ts index 6d58bf815d3db..895d3cf15430c 100644 --- a/packages/@aws-cdk/aws-codepipeline/lib/private/full-action-descriptor.ts +++ b/packages/@aws-cdk/aws-codepipeline/lib/private/full-action-descriptor.ts @@ -36,13 +36,13 @@ export class FullActionDescriptor { this.owner = actionProperties.owner || 'AWS'; this.provider = actionProperties.provider; this.version = actionProperties.version || '1'; - this.runOrder = actionProperties.runOrder === undefined ? 1 : actionProperties.runOrder; + this.runOrder = actionProperties.runOrder ?? 1; this.artifactBounds = actionProperties.artifactBounds; this.namespace = actionProperties.variablesNamespace; this.inputs = deduplicateArtifacts(actionProperties.inputs); this.outputs = deduplicateArtifacts(actionProperties.outputs); this.region = props.actionRegion || actionProperties.region; - this.role = actionProperties.role !== undefined ? actionProperties.role : props.actionRole; + this.role = actionProperties.role ?? props.actionRole; this.configuration = props.actionConfig.configuration; } diff --git a/packages/@aws-cdk/aws-cognito/lib/user-pool.ts b/packages/@aws-cdk/aws-cognito/lib/user-pool.ts index 960d14bb8b426..d85199ee6507f 100644 --- a/packages/@aws-cdk/aws-cognito/lib/user-pool.ts +++ b/packages/@aws-cdk/aws-cognito/lib/user-pool.ts @@ -723,7 +723,7 @@ export class UserPool extends UserPoolBase { emailSubject: props.userInvitation?.emailSubject, smsMessage: props.userInvitation?.smsMessage, }; - const selfSignUpEnabled = props.selfSignUpEnabled !== undefined ? props.selfSignUpEnabled : false; + const selfSignUpEnabled = props.selfSignUpEnabled ?? false; const adminCreateUserConfig: CfnUserPool.AdminCreateUserConfigProperty = { allowAdminCreateUserOnly: !selfSignUpEnabled, inviteMessageTemplate: props.userInvitation !== undefined ? inviteMessageTemplate : undefined, diff --git a/packages/@aws-cdk/aws-dynamodb/lib/table.ts b/packages/@aws-cdk/aws-dynamodb/lib/table.ts index b1c7c4f339ccd..1b12eef42de1f 100644 --- a/packages/@aws-cdk/aws-dynamodb/lib/table.ts +++ b/packages/@aws-cdk/aws-dynamodb/lib/table.ts @@ -1391,8 +1391,8 @@ export class Table extends TableBase { } return { - projectionType: props.projectionType ? props.projectionType : ProjectionType.ALL, - nonKeyAttributes: props.nonKeyAttributes ? props.nonKeyAttributes : undefined, + projectionType: props.projectionType ?? ProjectionType.ALL, + nonKeyAttributes: props.nonKeyAttributes ?? undefined, }; } diff --git a/packages/@aws-cdk/aws-ec2/lib/network-acl.ts b/packages/@aws-cdk/aws-ec2/lib/network-acl.ts index bea1b030d2c9a..911948e8df39c 100644 --- a/packages/@aws-cdk/aws-ec2/lib/network-acl.ts +++ b/packages/@aws-cdk/aws-ec2/lib/network-acl.ts @@ -277,7 +277,7 @@ export class NetworkAclEntry extends NetworkAclEntryBase { new CfnNetworkAclEntry(this, 'Resource', { networkAclId: this.networkAcl.networkAclId, ruleNumber: props.ruleNumber, - ruleAction: props.ruleAction !== undefined ? props.ruleAction : Action.ALLOW, + ruleAction: props.ruleAction ?? Action.ALLOW, egress: props.direction !== undefined ? props.direction === TrafficDirection.EGRESS : undefined, ...props.traffic.toTrafficConfig(), ...props.cidr.toCidrConfig(), diff --git a/packages/@aws-cdk/aws-ec2/lib/user-data.ts b/packages/@aws-cdk/aws-ec2/lib/user-data.ts index 21727212948c0..20061bd609636 100644 --- a/packages/@aws-cdk/aws-ec2/lib/user-data.ts +++ b/packages/@aws-cdk/aws-ec2/lib/user-data.ts @@ -147,7 +147,7 @@ class LinuxUserData extends UserData { } public render(): string { - const shebang = this.props.shebang !== undefined ? this.props.shebang : '#!/bin/bash'; + const shebang = this.props.shebang ?? '#!/bin/bash'; return [shebang, ...(this.renderOnExitLines()), ...this.lines].join('\n'); } diff --git a/packages/@aws-cdk/aws-ec2/lib/vpc-endpoint-service.ts b/packages/@aws-cdk/aws-ec2/lib/vpc-endpoint-service.ts index d17e56aab202c..87f67391f8c9b 100644 --- a/packages/@aws-cdk/aws-ec2/lib/vpc-endpoint-service.ts +++ b/packages/@aws-cdk/aws-ec2/lib/vpc-endpoint-service.ts @@ -86,8 +86,8 @@ export class VpcEndpointService extends Resource implements IVpcEndpointService } this.vpcEndpointServiceLoadBalancers = props.vpcEndpointServiceLoadBalancers; - this.acceptanceRequired = props.acceptanceRequired !== undefined ? props.acceptanceRequired : true; - this.whitelistedPrincipals = props.whitelistedPrincipals !== undefined ? props.whitelistedPrincipals : []; + this.acceptanceRequired = props.acceptanceRequired ?? true; + this.whitelistedPrincipals = props.whitelistedPrincipals ?? []; this.endpointService = new CfnVPCEndpointService(this, id, { networkLoadBalancerArns: this.vpcEndpointServiceLoadBalancers.map(lb => lb.loadBalancerArn), @@ -98,8 +98,7 @@ export class VpcEndpointService extends Resource implements IVpcEndpointService const { region } = Stack.of(this); const serviceNamePrefix = !Token.isUnresolved(region) ? - RegionInfo.get(region).vpcEndpointServiceNamePrefix ?? - Default.VPC_ENDPOINT_SERVICE_NAME_PREFIX : + (RegionInfo.get(region).vpcEndpointServiceNamePrefix ?? Default.VPC_ENDPOINT_SERVICE_NAME_PREFIX) : Default.VPC_ENDPOINT_SERVICE_NAME_PREFIX; this.vpcEndpointServiceName = Fn.join('.', [serviceNamePrefix, Aws.REGION, this.vpcEndpointServiceId]); diff --git a/packages/@aws-cdk/aws-ec2/lib/vpc.ts b/packages/@aws-cdk/aws-ec2/lib/vpc.ts index d23433b2637d8..4e3f90780db4c 100644 --- a/packages/@aws-cdk/aws-ec2/lib/vpc.ts +++ b/packages/@aws-cdk/aws-ec2/lib/vpc.ts @@ -1213,7 +1213,7 @@ export class Vpc extends VpcBase { this.availabilityZones = stack.availabilityZones; - const maxAZs = props.maxAzs !== undefined ? props.maxAzs : 3; + const maxAZs = props.maxAzs ?? 3; this.availabilityZones = this.availabilityZones.slice(0, maxAZs); this.vpcId = this.resource.ref; @@ -1788,7 +1788,7 @@ export class PrivateSubnet extends Subnet implements IPrivateSubnet { } function ifUndefined(value: T | undefined, defaultValue: T): T { - return value !== undefined ? value : defaultValue; + return value ?? defaultValue; } class ImportedVpc extends VpcBase { diff --git a/packages/@aws-cdk/aws-ecr/lib/repository.ts b/packages/@aws-cdk/aws-ecr/lib/repository.ts index 36e14cf861adc..83c05ba1ed308 100644 --- a/packages/@aws-cdk/aws-ecr/lib/repository.ts +++ b/packages/@aws-cdk/aws-ecr/lib/repository.ts @@ -202,7 +202,7 @@ export abstract class RepositoryBase extends Resource implements IRepository { detail: { 'repository-name': [this.repositoryName], 'scan-status': ['COMPLETE'], - 'image-tags': options.imageTags ? options.imageTags : undefined, + 'image-tags': options.imageTags ?? undefined, }, }); return rule; @@ -526,7 +526,7 @@ export class Repository extends RepositoryBase { for (const rule of prioritizedRules.concat(autoPrioritizedRules).concat(anyRules)) { ret.push({ ...rule, - rulePriority: rule.rulePriority !== undefined ? rule.rulePriority : autoPrio++, + rulePriority: rule.rulePriority ?? autoPrio++, }); } @@ -557,7 +557,7 @@ function renderLifecycleRule(rule: LifecycleRule) { tagStatus: rule.tagStatus || TagStatus.ANY, tagPrefixList: rule.tagPrefixList, countType: rule.maxImageAge !== undefined ? CountType.SINCE_IMAGE_PUSHED : CountType.IMAGE_COUNT_MORE_THAN, - countNumber: rule.maxImageAge !== undefined ? rule.maxImageAge.toDays() : rule.maxImageCount, + countNumber: rule.maxImageAge?.toDays() ?? rule.maxImageCount, countUnit: rule.maxImageAge !== undefined ? 'days' : undefined, }, action: { diff --git a/packages/@aws-cdk/aws-ecs-patterns/lib/base/application-load-balanced-service-base.ts b/packages/@aws-cdk/aws-ecs-patterns/lib/base/application-load-balanced-service-base.ts index 769756999ad0c..74411bb217558 100644 --- a/packages/@aws-cdk/aws-ecs-patterns/lib/base/application-load-balanced-service-base.ts +++ b/packages/@aws-cdk/aws-ecs-patterns/lib/base/application-load-balanced-service-base.ts @@ -370,21 +370,19 @@ export abstract class ApplicationLoadBalancedServiceBase extends CoreConstruct { } this.desiredCount = props.desiredCount || 1; - const internetFacing = props.publicLoadBalancer !== undefined ? props.publicLoadBalancer : true; + const internetFacing = props.publicLoadBalancer ?? true; const lbProps = { vpc: this.cluster.vpc, internetFacing, }; - const loadBalancer = props.loadBalancer !== undefined ? props.loadBalancer - : new ApplicationLoadBalancer(this, 'LB', lbProps); + const loadBalancer = props.loadBalancer ?? new ApplicationLoadBalancer(this, 'LB', lbProps); if (props.certificate !== undefined && props.protocol !== undefined && props.protocol !== ApplicationProtocol.HTTPS) { throw new Error('The HTTPS protocol must be used when a certificate is given'); } - const protocol = props.protocol !== undefined ? props.protocol : - (props.certificate ? ApplicationProtocol.HTTPS : ApplicationProtocol.HTTP); + const protocol = props.protocol ?? (props.certificate ? ApplicationProtocol.HTTPS : ApplicationProtocol.HTTP); if (protocol !== ApplicationProtocol.HTTPS && props.redirectHTTP === true) { throw new Error('The HTTPS protocol must be used when redirecting HTTP traffic'); diff --git a/packages/@aws-cdk/aws-ecs-patterns/lib/base/application-multiple-target-groups-service-base.ts b/packages/@aws-cdk/aws-ecs-patterns/lib/base/application-multiple-target-groups-service-base.ts index 67ce9a02e77b6..f3eb132e934ae 100644 --- a/packages/@aws-cdk/aws-ecs-patterns/lib/base/application-multiple-target-groups-service-base.ts +++ b/packages/@aws-cdk/aws-ecs-patterns/lib/base/application-multiple-target-groups-service-base.ts @@ -478,10 +478,8 @@ export abstract class ApplicationMultipleTargetGroupsServiceBase extends CoreCon * Create log driver if logging is enabled. */ private createLogDriver(enableLoggingProp?: boolean, logDriverProp?: LogDriver): LogDriver | undefined { - const enableLogging = enableLoggingProp !== undefined ? enableLoggingProp : true; - const logDriver = logDriverProp !== undefined - ? logDriverProp : enableLogging - ? this.createAWSLogDriver(this.node.id) : undefined; + const enableLogging = enableLoggingProp ?? true; + const logDriver = logDriverProp ?? (enableLogging ? this.createAWSLogDriver(this.node.id) : undefined); return logDriver; } @@ -522,7 +520,7 @@ export abstract class ApplicationMultipleTargetGroupsServiceBase extends CoreCon } private createLoadBalancer(name: string, publicLoadBalancer?: boolean): ApplicationLoadBalancer { - const internetFacing = publicLoadBalancer !== undefined ? publicLoadBalancer : true; + const internetFacing = publicLoadBalancer ?? true; const lbProps = { vpc: this.cluster.vpc, internetFacing, @@ -532,7 +530,7 @@ export abstract class ApplicationMultipleTargetGroupsServiceBase extends CoreCon } private createListenerProtocol(listenerProtocol?: ApplicationProtocol, certificate?: ICertificate): ApplicationProtocol { - return listenerProtocol !== undefined ? listenerProtocol : (certificate ? ApplicationProtocol.HTTPS : ApplicationProtocol.HTTP); + return listenerProtocol ?? (certificate ? ApplicationProtocol.HTTPS : ApplicationProtocol.HTTP); } private createListenerCertificate(listenerName: string, certificate?: ICertificate, domainName?: string, domainZone?: IHostedZone): ICertificate { diff --git a/packages/@aws-cdk/aws-ecs-patterns/lib/base/network-load-balanced-service-base.ts b/packages/@aws-cdk/aws-ecs-patterns/lib/base/network-load-balanced-service-base.ts index ffdcb3b75912a..656cc19d19d43 100644 --- a/packages/@aws-cdk/aws-ecs-patterns/lib/base/network-load-balanced-service-base.ts +++ b/packages/@aws-cdk/aws-ecs-patterns/lib/base/network-load-balanced-service-base.ts @@ -308,18 +308,15 @@ export abstract class NetworkLoadBalancedServiceBase extends CoreConstruct { } this.desiredCount = props.desiredCount || 1; - const internetFacing = props.publicLoadBalancer !== undefined ? props.publicLoadBalancer : true; + const internetFacing = props.publicLoadBalancer ?? true; const lbProps = { vpc: this.cluster.vpc, internetFacing, }; - const loadBalancer = props.loadBalancer !== undefined ? props.loadBalancer : - new NetworkLoadBalancer(this, 'LB', lbProps); - - const listenerPort = props.listenerPort !== undefined ? props.listenerPort : 80; - + const loadBalancer = props.loadBalancer ?? new NetworkLoadBalancer(this, 'LB', lbProps); + const listenerPort = props.listenerPort ?? 80; const targetProps = { port: 80, }; diff --git a/packages/@aws-cdk/aws-ecs-patterns/lib/base/network-multiple-target-groups-service-base.ts b/packages/@aws-cdk/aws-ecs-patterns/lib/base/network-multiple-target-groups-service-base.ts index d3f74588fd341..d34a6b548076d 100644 --- a/packages/@aws-cdk/aws-ecs-patterns/lib/base/network-multiple-target-groups-service-base.ts +++ b/packages/@aws-cdk/aws-ecs-patterns/lib/base/network-multiple-target-groups-service-base.ts @@ -384,10 +384,8 @@ export abstract class NetworkMultipleTargetGroupsServiceBase extends CoreConstru * Create log driver if logging is enabled. */ private createLogDriver(enableLoggingProp?: boolean, logDriverProp?: LogDriver): LogDriver | undefined { - const enableLogging = enableLoggingProp !== undefined ? enableLoggingProp : true; - const logDriver = logDriverProp !== undefined - ? logDriverProp : enableLogging - ? this.createAWSLogDriver(this.node.id) : undefined; + const enableLogging = enableLoggingProp ?? true; + const logDriver = logDriverProp ?? (enableLogging ? this.createAWSLogDriver(this.node.id) : undefined); return logDriver; } @@ -413,7 +411,7 @@ export abstract class NetworkMultipleTargetGroupsServiceBase extends CoreConstru } private createLoadBalancer(name: string, publicLoadBalancer?: boolean): NetworkLoadBalancer { - const internetFacing = publicLoadBalancer !== undefined ? publicLoadBalancer : true; + const internetFacing = publicLoadBalancer ?? true; const lbProps = { vpc: this.cluster.vpc, internetFacing, diff --git a/packages/@aws-cdk/aws-ecs-patterns/lib/base/queue-processing-service-base.ts b/packages/@aws-cdk/aws-ecs-patterns/lib/base/queue-processing-service-base.ts index 66bdea9619629..3248514931f4d 100644 --- a/packages/@aws-cdk/aws-ecs-patterns/lib/base/queue-processing-service-base.ts +++ b/packages/@aws-cdk/aws-ecs-patterns/lib/base/queue-processing-service-base.ts @@ -262,22 +262,18 @@ export abstract class QueueProcessingServiceBase extends CoreConstruct { // Setup autoscaling scaling intervals const defaultScalingSteps = [{ upper: 0, change: -1 }, { lower: 100, change: +1 }, { lower: 500, change: +5 }]; - this.scalingSteps = props.scalingSteps !== undefined ? props.scalingSteps : defaultScalingSteps; + this.scalingSteps = props.scalingSteps ?? defaultScalingSteps; // Create log driver if logging is enabled - const enableLogging = props.enableLogging !== undefined ? props.enableLogging : true; - this.logDriver = props.logDriver !== undefined - ? props.logDriver - : enableLogging - ? this.createAWSLogDriver(this.node.id) - : undefined; + const enableLogging = props.enableLogging ?? true; + this.logDriver = props.logDriver ?? (enableLogging ? this.createAWSLogDriver(this.node.id) : undefined); // Add the queue name to environment variables this.environment = { ...(props.environment || {}), QUEUE_NAME: this.sqsQueue.queueName }; this.secrets = props.secrets; // Determine the desired task count (minimum) and maximum scaling capacity - this.desiredCount = props.desiredTaskCount !== undefined ? props.desiredTaskCount : 1; + this.desiredCount = props.desiredTaskCount ?? 1; this.maxCapacity = props.maxScalingCapacity || (2 * this.desiredCount); if (!this.desiredCount && !this.maxCapacity) { diff --git a/packages/@aws-cdk/aws-ecs-patterns/lib/ecs/application-load-balanced-ecs-service.ts b/packages/@aws-cdk/aws-ecs-patterns/lib/ecs/application-load-balanced-ecs-service.ts index 9cec9e1d9e083..b9bdcf2d100ad 100644 --- a/packages/@aws-cdk/aws-ecs-patterns/lib/ecs/application-load-balanced-ecs-service.ts +++ b/packages/@aws-cdk/aws-ecs-patterns/lib/ecs/application-load-balanced-ecs-service.ts @@ -97,12 +97,10 @@ export class ApplicationLoadBalancedEc2Service extends ApplicationLoadBalancedSe }); // Create log driver if logging is enabled - const enableLogging = taskImageOptions.enableLogging !== undefined ? taskImageOptions.enableLogging : true; - const logDriver = taskImageOptions.logDriver !== undefined - ? taskImageOptions.logDriver : enableLogging - ? this.createAWSLogDriver(this.node.id) : undefined; + const enableLogging = taskImageOptions.enableLogging ?? true; + const logDriver = taskImageOptions.logDriver ?? (enableLogging ? this.createAWSLogDriver(this.node.id) : undefined); - const containerName = taskImageOptions.containerName !== undefined ? taskImageOptions.containerName : 'web'; + const containerName = taskImageOptions.containerName ?? 'web'; const container = this.taskDefinition.addContainer(containerName, { image: taskImageOptions.image, cpu: props.cpu, diff --git a/packages/@aws-cdk/aws-ecs-patterns/lib/ecs/application-multiple-target-groups-ecs-service.ts b/packages/@aws-cdk/aws-ecs-patterns/lib/ecs/application-multiple-target-groups-ecs-service.ts index 4e6fa5c04b6f3..6ed6b6b71802f 100644 --- a/packages/@aws-cdk/aws-ecs-patterns/lib/ecs/application-multiple-target-groups-ecs-service.ts +++ b/packages/@aws-cdk/aws-ecs-patterns/lib/ecs/application-multiple-target-groups-ecs-service.ts @@ -94,7 +94,7 @@ export class ApplicationMultipleTargetGroupsEc2Service extends ApplicationMultip taskRole: taskImageOptions.taskRole, }); - const containerName = taskImageOptions.containerName !== undefined ? taskImageOptions.containerName : 'web'; + const containerName = taskImageOptions.containerName ?? 'web'; const container = this.taskDefinition.addContainer(containerName, { image: taskImageOptions.image, cpu: props.cpu, diff --git a/packages/@aws-cdk/aws-ecs-patterns/lib/ecs/network-load-balanced-ecs-service.ts b/packages/@aws-cdk/aws-ecs-patterns/lib/ecs/network-load-balanced-ecs-service.ts index 2d2c00fcf345e..fae46b68e7380 100644 --- a/packages/@aws-cdk/aws-ecs-patterns/lib/ecs/network-load-balanced-ecs-service.ts +++ b/packages/@aws-cdk/aws-ecs-patterns/lib/ecs/network-load-balanced-ecs-service.ts @@ -95,12 +95,10 @@ export class NetworkLoadBalancedEc2Service extends NetworkLoadBalancedServiceBas }); // Create log driver if logging is enabled - const enableLogging = taskImageOptions.enableLogging !== undefined ? taskImageOptions.enableLogging : true; - const logDriver = taskImageOptions.logDriver !== undefined - ? taskImageOptions.logDriver : enableLogging - ? this.createAWSLogDriver(this.node.id) : undefined; + const enableLogging = taskImageOptions.enableLogging ?? true; + const logDriver = taskImageOptions.logDriver ?? (enableLogging ? this.createAWSLogDriver(this.node.id) : undefined); - const containerName = taskImageOptions.containerName !== undefined ? taskImageOptions.containerName : 'web'; + const containerName = taskImageOptions.containerName ?? 'web'; const container = this.taskDefinition.addContainer(containerName, { image: taskImageOptions.image, cpu: props.cpu, diff --git a/packages/@aws-cdk/aws-ecs-patterns/lib/ecs/network-multiple-target-groups-ecs-service.ts b/packages/@aws-cdk/aws-ecs-patterns/lib/ecs/network-multiple-target-groups-ecs-service.ts index a283c9ab55dec..eb8392d3b2148 100644 --- a/packages/@aws-cdk/aws-ecs-patterns/lib/ecs/network-multiple-target-groups-ecs-service.ts +++ b/packages/@aws-cdk/aws-ecs-patterns/lib/ecs/network-multiple-target-groups-ecs-service.ts @@ -93,7 +93,7 @@ export class NetworkMultipleTargetGroupsEc2Service extends NetworkMultipleTarget taskRole: taskImageOptions.taskRole, }); - const containerName = taskImageOptions.containerName !== undefined ? taskImageOptions.containerName : 'web'; + const containerName = taskImageOptions.containerName ?? 'web'; const container = this.taskDefinition.addContainer(containerName, { image: taskImageOptions.image, cpu: props.cpu, diff --git a/packages/@aws-cdk/aws-ecs-patterns/lib/ecs/scheduled-ecs-task.ts b/packages/@aws-cdk/aws-ecs-patterns/lib/ecs/scheduled-ecs-task.ts index 7350ae82bb2cc..7f64a18df9ff8 100644 --- a/packages/@aws-cdk/aws-ecs-patterns/lib/ecs/scheduled-ecs-task.ts +++ b/packages/@aws-cdk/aws-ecs-patterns/lib/ecs/scheduled-ecs-task.ts @@ -107,7 +107,7 @@ export class ScheduledEc2Task extends ScheduledTaskBase { command: taskImageOptions.command, environment: taskImageOptions.environment, secrets: taskImageOptions.secrets, - logging: taskImageOptions.logDriver !== undefined ? taskImageOptions.logDriver : this.createAWSLogDriver(this.node.id), + logging: taskImageOptions.logDriver ?? this.createAWSLogDriver(this.node.id), }); } else { throw new Error('You must specify a taskDefinition or image'); diff --git a/packages/@aws-cdk/aws-ecs-patterns/lib/fargate/application-load-balanced-fargate-service.ts b/packages/@aws-cdk/aws-ecs-patterns/lib/fargate/application-load-balanced-fargate-service.ts index 00049e662ee0f..2ae468bcae558 100644 --- a/packages/@aws-cdk/aws-ecs-patterns/lib/fargate/application-load-balanced-fargate-service.ts +++ b/packages/@aws-cdk/aws-ecs-patterns/lib/fargate/application-load-balanced-fargate-service.ts @@ -117,7 +117,7 @@ export class ApplicationLoadBalancedFargateService extends ApplicationLoadBalanc constructor(scope: Construct, id: string, props: ApplicationLoadBalancedFargateServiceProps = {}) { super(scope, id, props); - this.assignPublicIp = props.assignPublicIp !== undefined ? props.assignPublicIp : false; + this.assignPublicIp = props.assignPublicIp ?? false; if (props.taskDefinition && props.taskImageOptions) { throw new Error('You must specify either a taskDefinition or an image, not both.'); @@ -134,12 +134,12 @@ export class ApplicationLoadBalancedFargateService extends ApplicationLoadBalanc }); // Create log driver if logging is enabled - const enableLogging = taskImageOptions.enableLogging !== undefined ? taskImageOptions.enableLogging : true; + const enableLogging = taskImageOptions.enableLogging ?? true; const logDriver = taskImageOptions.logDriver !== undefined ? taskImageOptions.logDriver : enableLogging ? this.createAWSLogDriver(this.node.id) : undefined; - const containerName = taskImageOptions.containerName !== undefined ? taskImageOptions.containerName : 'web'; + const containerName = taskImageOptions.containerName ?? 'web'; const container = this.taskDefinition.addContainer(containerName, { image: taskImageOptions.image, logging: logDriver, diff --git a/packages/@aws-cdk/aws-ecs-patterns/lib/fargate/application-multiple-target-groups-fargate-service.ts b/packages/@aws-cdk/aws-ecs-patterns/lib/fargate/application-multiple-target-groups-fargate-service.ts index a5840bc2f2e76..495049dfccfa8 100644 --- a/packages/@aws-cdk/aws-ecs-patterns/lib/fargate/application-multiple-target-groups-fargate-service.ts +++ b/packages/@aws-cdk/aws-ecs-patterns/lib/fargate/application-multiple-target-groups-fargate-service.ts @@ -113,7 +113,7 @@ export class ApplicationMultipleTargetGroupsFargateService extends ApplicationMu constructor(scope: Construct, id: string, props: ApplicationMultipleTargetGroupsFargateServiceProps = {}) { super(scope, id, props); - this.assignPublicIp = props.assignPublicIp !== undefined ? props.assignPublicIp : false; + this.assignPublicIp = props.assignPublicIp ?? false; if (props.taskDefinition && props.taskImageOptions) { throw new Error('You must specify only one of TaskDefinition or TaskImageOptions.'); @@ -129,7 +129,7 @@ export class ApplicationMultipleTargetGroupsFargateService extends ApplicationMu family: taskImageOptions.family, }); - const containerName = taskImageOptions.containerName !== undefined ? taskImageOptions.containerName : 'web'; + const containerName = taskImageOptions.containerName ?? 'web'; const container = this.taskDefinition.addContainer(containerName, { image: taskImageOptions.image, logging: this.logDriver, diff --git a/packages/@aws-cdk/aws-ecs-patterns/lib/fargate/network-load-balanced-fargate-service.ts b/packages/@aws-cdk/aws-ecs-patterns/lib/fargate/network-load-balanced-fargate-service.ts index 10dcfebdc2f80..4aad4b31e7efe 100644 --- a/packages/@aws-cdk/aws-ecs-patterns/lib/fargate/network-load-balanced-fargate-service.ts +++ b/packages/@aws-cdk/aws-ecs-patterns/lib/fargate/network-load-balanced-fargate-service.ts @@ -106,7 +106,7 @@ export class NetworkLoadBalancedFargateService extends NetworkLoadBalancedServic constructor(scope: Construct, id: string, props: NetworkLoadBalancedFargateServiceProps = {}) { super(scope, id, props); - this.assignPublicIp = props.assignPublicIp !== undefined ? props.assignPublicIp : false; + this.assignPublicIp = props.assignPublicIp ?? false; if (props.taskDefinition && props.taskImageOptions) { throw new Error('You must specify either a taskDefinition or an image, not both.'); @@ -123,12 +123,10 @@ export class NetworkLoadBalancedFargateService extends NetworkLoadBalancedServic }); // Create log driver if logging is enabled - const enableLogging = taskImageOptions.enableLogging !== undefined ? taskImageOptions.enableLogging : true; - const logDriver = taskImageOptions.logDriver !== undefined - ? taskImageOptions.logDriver : enableLogging - ? this.createAWSLogDriver(this.node.id) : undefined; + const enableLogging = taskImageOptions.enableLogging ?? true; + const logDriver = taskImageOptions.logDriver ?? (enableLogging ? this.createAWSLogDriver(this.node.id) : undefined); - const containerName = taskImageOptions.containerName !== undefined ? taskImageOptions.containerName : 'web'; + const containerName = taskImageOptions.containerName ?? 'web'; const container = this.taskDefinition.addContainer(containerName, { image: taskImageOptions.image, logging: logDriver, diff --git a/packages/@aws-cdk/aws-ecs-patterns/lib/fargate/network-multiple-target-groups-fargate-service.ts b/packages/@aws-cdk/aws-ecs-patterns/lib/fargate/network-multiple-target-groups-fargate-service.ts index 0d97d730daeab..dab033b1938ce 100644 --- a/packages/@aws-cdk/aws-ecs-patterns/lib/fargate/network-multiple-target-groups-fargate-service.ts +++ b/packages/@aws-cdk/aws-ecs-patterns/lib/fargate/network-multiple-target-groups-fargate-service.ts @@ -113,7 +113,7 @@ export class NetworkMultipleTargetGroupsFargateService extends NetworkMultipleTa constructor(scope: Construct, id: string, props: NetworkMultipleTargetGroupsFargateServiceProps = {}) { super(scope, id, props); - this.assignPublicIp = props.assignPublicIp !== undefined ? props.assignPublicIp : false; + this.assignPublicIp = props.assignPublicIp ?? false; if (props.taskDefinition && props.taskImageOptions) { throw new Error('You must specify only one of TaskDefinition or TaskImageOptions.'); @@ -129,7 +129,7 @@ export class NetworkMultipleTargetGroupsFargateService extends NetworkMultipleTa family: taskImageOptions.family, }); - const containerName = taskImageOptions.containerName !== undefined ? taskImageOptions.containerName : 'web'; + const containerName = taskImageOptions.containerName ?? 'web'; const container = this.taskDefinition.addContainer(containerName, { image: taskImageOptions.image, logging: this.logDriver, diff --git a/packages/@aws-cdk/aws-ecs-patterns/lib/fargate/scheduled-fargate-task.ts b/packages/@aws-cdk/aws-ecs-patterns/lib/fargate/scheduled-fargate-task.ts index 27b9d8b6ad224..ab46883fa9c90 100644 --- a/packages/@aws-cdk/aws-ecs-patterns/lib/fargate/scheduled-fargate-task.ts +++ b/packages/@aws-cdk/aws-ecs-patterns/lib/fargate/scheduled-fargate-task.ts @@ -115,7 +115,7 @@ export class ScheduledFargateTask extends ScheduledTaskBase { command: taskImageOptions.command, environment: taskImageOptions.environment, secrets: taskImageOptions.secrets, - logging: taskImageOptions.logDriver !== undefined ? taskImageOptions.logDriver : this.createAWSLogDriver(this.node.id), + logging: taskImageOptions.logDriver ?? this.createAWSLogDriver(this.node.id), }); } else { throw new Error('You must specify one of: taskDefinition or image'); diff --git a/packages/@aws-cdk/aws-ecs/lib/base/base-service.ts b/packages/@aws-cdk/aws-ecs/lib/base/base-service.ts index 6704ab8d79ca9..5c5160a849835 100644 --- a/packages/@aws-cdk/aws-ecs/lib/base/base-service.ts +++ b/packages/@aws-cdk/aws-ecs/lib/base/base-service.ts @@ -234,8 +234,7 @@ class ApplicationListenerConfig extends ListenerConfig { public addTargets(id: string, target: LoadBalancerTargetOptions, service: BaseService) { const props = this.props || {}; const protocol = props.protocol; - const port = props.port !== undefined ? props.port : (protocol === undefined ? 80 : - (protocol === elbv2.ApplicationProtocol.HTTPS ? 443 : 80)); + const port = props.port ?? (protocol === elbv2.ApplicationProtocol.HTTPS ? 443 : 80); this.listener.addTargets(id, { ... props, targets: [ @@ -260,7 +259,7 @@ class NetworkListenerConfig extends ListenerConfig { * Create and attach a target group to listener. */ public addTargets(id: string, target: LoadBalancerTargetOptions, service: BaseService) { - const port = this.props !== undefined ? this.props.port : 80; + const port = this.props?.port ?? 80; this.listener.addTargets(id, { ... this.props, targets: [ @@ -370,7 +369,7 @@ export abstract class BaseService extends Resource } : undefined, }, propagateTags: props.propagateTags === PropagatedTagSource.NONE ? undefined : props.propagateTags, - enableEcsManagedTags: props.enableECSManagedTags === undefined ? false : props.enableECSManagedTags, + enableEcsManagedTags: props.enableECSManagedTags ?? false, deploymentController: props.deploymentController, launchType: props.deploymentController?.type === DeploymentControllerType.EXTERNAL ? undefined : props.launchType, healthCheckGracePeriodSeconds: this.evaluateHealthGracePeriod(props.healthCheckGracePeriod), @@ -525,7 +524,7 @@ export abstract class BaseService extends Resource * @returns The created CloudMap service */ public enableCloudMap(options: CloudMapOptions): cloudmap.Service { - const sdNamespace = options.cloudMapNamespace !== undefined ? options.cloudMapNamespace : this.cluster.defaultCloudMapNamespace; + const sdNamespace = options.cloudMapNamespace ?? this.cluster.defaultCloudMapNamespace; if (sdNamespace === undefined) { throw new Error('Cannot enable service discovery if a Cloudmap Namespace has not been created in the cluster.'); } @@ -739,9 +738,7 @@ export abstract class BaseService extends Resource */ private evaluateHealthGracePeriod(providedHealthCheckGracePeriod?: Duration): IResolvable { return Lazy.any({ - produce: () => providedHealthCheckGracePeriod !== undefined ? providedHealthCheckGracePeriod.toSeconds() : - this.loadBalancers.length > 0 ? 60 : - undefined, + produce: () => providedHealthCheckGracePeriod?.toSeconds() ?? (this.loadBalancers.length > 0 ? 60 : undefined), }); } } diff --git a/packages/@aws-cdk/aws-ecs/lib/base/task-definition.ts b/packages/@aws-cdk/aws-ecs/lib/base/task-definition.ts index ff27f00cb79a8..f7b0f05c92800 100644 --- a/packages/@aws-cdk/aws-ecs/lib/base/task-definition.ts +++ b/packages/@aws-cdk/aws-ecs/lib/base/task-definition.ts @@ -284,8 +284,7 @@ export class TaskDefinition extends TaskDefinitionBase { props.volumes.forEach(v => this.addVolume(v)); } - this.networkMode = props.networkMode !== undefined ? props.networkMode : - this.isFargateCompatible ? NetworkMode.AWS_VPC : NetworkMode.BRIDGE; + this.networkMode = props.networkMode ?? (this.isFargateCompatible ? NetworkMode.AWS_VPC : NetworkMode.BRIDGE); if (this.isFargateCompatible && this.networkMode !== NetworkMode.AWS_VPC) { throw new Error(`Fargate tasks can only have AwsVpc network mode, got: ${this.networkMode}`); } diff --git a/packages/@aws-cdk/aws-ecs/lib/cluster.ts b/packages/@aws-cdk/aws-ecs/lib/cluster.ts index fcc28784229e5..ca84679e7b970 100644 --- a/packages/@aws-cdk/aws-ecs/lib/cluster.ts +++ b/packages/@aws-cdk/aws-ecs/lib/cluster.ts @@ -790,7 +790,7 @@ class ImportedCluster extends Resource implements ICluster { this.hasEc2Capacity = props.hasEc2Capacity !== false; this._defaultCloudMapNamespace = props.defaultCloudMapNamespace; - this.clusterArn = props.clusterArn !== undefined ? props.clusterArn : Stack.of(this).formatArn({ + this.clusterArn = props.clusterArn ?? Stack.of(this).formatArn({ service: 'ecs', resource: 'cluster', resourceName: props.clusterName, diff --git a/packages/@aws-cdk/aws-ecs/lib/container-definition.ts b/packages/@aws-cdk/aws-ecs/lib/container-definition.ts index b4d31c56133fc..983489743482f 100644 --- a/packages/@aws-cdk/aws-ecs/lib/container-definition.ts +++ b/packages/@aws-cdk/aws-ecs/lib/container-definition.ts @@ -399,7 +399,7 @@ export class ContainerDefinition extends CoreConstruct { throw new Error('MemoryLimitMiB should not be less than MemoryReservationMiB.'); } } - this.essential = props.essential !== undefined ? props.essential : true; + this.essential = props.essential ?? true; this.taskDefinition = props.taskDefinition; this.memoryLimitSpecified = props.memoryLimitMiB !== undefined || props.memoryReservationMiB !== undefined; this.linuxParameters = props.linuxParameters; @@ -705,10 +705,10 @@ function renderEnvironmentFiles(environmentFiles: EnvironmentFileConfig[]): any[ function renderHealthCheck(hc: HealthCheck): CfnTaskDefinition.HealthCheckProperty { return { command: getHealthCheckCommand(hc), - interval: hc.interval != null ? hc.interval.toSeconds() : 30, - retries: hc.retries !== undefined ? hc.retries : 3, - startPeriod: hc.startPeriod && hc.startPeriod.toSeconds(), - timeout: hc.timeout !== undefined ? hc.timeout.toSeconds() : 5, + interval: hc.interval?.toSeconds() ?? 30, + retries: hc.retries ?? 3, + startPeriod: hc.startPeriod?.toSeconds(), + timeout: hc.timeout?.toSeconds() ?? 5, }; } diff --git a/packages/@aws-cdk/aws-ecs/lib/ec2/ec2-service.ts b/packages/@aws-cdk/aws-ecs/lib/ec2/ec2-service.ts index a119e445e6571..18c6df350fb4e 100644 --- a/packages/@aws-cdk/aws-ecs/lib/ec2/ec2-service.ts +++ b/packages/@aws-cdk/aws-ecs/lib/ec2/ec2-service.ts @@ -181,8 +181,7 @@ export class Ec2Service extends BaseService implements IEc2Service { throw new Error('Only one of SecurityGroup or SecurityGroups can be populated.'); } - const propagateTagsFromSource = props.propagateTaskTagsFrom !== undefined ? props.propagateTaskTagsFrom - : (props.propagateTags !== undefined ? props.propagateTags : PropagatedTagSource.NONE); + const propagateTagsFromSource = props.propagateTaskTagsFrom ?? props.propagateTags ?? PropagatedTagSource.NONE; super(scope, id, { ...props, diff --git a/packages/@aws-cdk/aws-ecs/lib/fargate/fargate-service.ts b/packages/@aws-cdk/aws-ecs/lib/fargate/fargate-service.ts index f70ca796ed3f6..01a9f75665c57 100644 --- a/packages/@aws-cdk/aws-ecs/lib/fargate/fargate-service.ts +++ b/packages/@aws-cdk/aws-ecs/lib/fargate/fargate-service.ts @@ -147,8 +147,7 @@ export class FargateService extends BaseService implements IFargateService { throw new Error(`The task definition of this service uses at least one container that references a secret JSON field. This feature requires platform version ${FargatePlatformVersion.VERSION1_4} or later.`); } - const propagateTagsFromSource = props.propagateTaskTagsFrom !== undefined ? props.propagateTaskTagsFrom - : (props.propagateTags !== undefined ? props.propagateTags : PropagatedTagSource.NONE); + const propagateTagsFromSource = props.propagateTaskTagsFrom ?? props.propagateTags ?? PropagatedTagSource.NONE; super(scope, id, { ...props, diff --git a/packages/@aws-cdk/aws-eks-legacy/lib/cluster.ts b/packages/@aws-cdk/aws-eks-legacy/lib/cluster.ts index a00358d7395ce..1f8c699180aad 100644 --- a/packages/@aws-cdk/aws-eks-legacy/lib/cluster.ts +++ b/packages/@aws-cdk/aws-eks-legacy/lib/cluster.ts @@ -382,7 +382,7 @@ export class Cluster extends Resource implements ICluster { }; let resource; - this.kubectlEnabled = props.kubectlEnabled === undefined ? true : props.kubectlEnabled; + this.kubectlEnabled = props.kubectlEnabled ?? true; if (this.kubectlEnabled) { resource = new ClusterResource(this, 'Resource', clusterProps); this._defaultMastersRole = resource.creationRole; @@ -429,13 +429,13 @@ export class Cluster extends Resource implements ICluster { } // allocate default capacity if non-zero (or default). - const desiredCapacity = props.defaultCapacity === undefined ? DEFAULT_CAPACITY_COUNT : props.defaultCapacity; + const desiredCapacity = props.defaultCapacity ?? DEFAULT_CAPACITY_COUNT; if (desiredCapacity > 0) { const instanceType = props.defaultCapacityInstance || DEFAULT_CAPACITY_TYPE; this.defaultCapacity = this.addCapacity('DefaultCapacity', { instanceType, desiredCapacity }); } - const outputConfigCommand = props.outputConfigCommand === undefined ? true : props.outputConfigCommand; + const outputConfigCommand = props.outputConfigCommand ?? true; if (outputConfigCommand) { const postfix = commonCommandOptions.join(' '); new CfnOutput(this, 'ConfigCommand', { value: `${updateConfigCommandPrefix} ${postfix}` }); @@ -512,7 +512,7 @@ export class Cluster extends Resource implements ICluster { autoScalingGroup.connections.allowToAnyIpv4(ec2.Port.allUdp()); autoScalingGroup.connections.allowToAnyIpv4(ec2.Port.allIcmp()); - const bootstrapEnabled = options.bootstrapEnabled !== undefined ? options.bootstrapEnabled : true; + const bootstrapEnabled = options.bootstrapEnabled ?? true; if (options.bootstrapOptions && !bootstrapEnabled) { throw new Error('Cannot specify "bootstrapOptions" if "bootstrapEnabled" is false'); } @@ -537,7 +537,7 @@ export class Cluster extends Resource implements ICluster { // do not attempt to map the role if `kubectl` is not enabled for this // cluster or if `mapRole` is set to false. By default this should happen. - const mapRole = options.mapRole === undefined ? true : options.mapRole; + const mapRole = options.mapRole ?? true; if (mapRole && this.kubectlEnabled) { // see https://docs.aws.amazon.com/en_us/eks/latest/userguide/add-user-role.html this.awsAuth.addRoleMapping(autoScalingGroup.role, { diff --git a/packages/@aws-cdk/aws-eks-legacy/lib/user-data.ts b/packages/@aws-cdk/aws-eks-legacy/lib/user-data.ts index e889663520f32..75d6e009d657a 100644 --- a/packages/@aws-cdk/aws-eks-legacy/lib/user-data.ts +++ b/packages/@aws-cdk/aws-eks-legacy/lib/user-data.ts @@ -12,7 +12,7 @@ export function renderUserData(clusterName: string, autoScalingGroup: autoscalin const extraArgs = new Array(); - extraArgs.push(`--use-max-pods ${options.useMaxPods === undefined ? true : options.useMaxPods}`); + extraArgs.push(`--use-max-pods ${options.useMaxPods ?? true}`); if (options.awsApiRetryAttempts) { extraArgs.push(`--aws-api-retry-attempts ${options.awsApiRetryAttempts}`); diff --git a/packages/@aws-cdk/aws-eks/lib/cluster.ts b/packages/@aws-cdk/aws-eks/lib/cluster.ts index 6737ac1c7f604..706a23720c157 100644 --- a/packages/@aws-cdk/aws-eks/lib/cluster.ts +++ b/packages/@aws-cdk/aws-eks/lib/cluster.ts @@ -1105,7 +1105,7 @@ export class Cluster extends ClusterBase { commonCommandOptions.push(`--role-arn ${mastersRole.roleArn}`); // allocate default capacity if non-zero (or default). - const minCapacity = props.defaultCapacity === undefined ? DEFAULT_CAPACITY_COUNT : props.defaultCapacity; + const minCapacity = props.defaultCapacity ?? DEFAULT_CAPACITY_COUNT; if (minCapacity > 0) { const instanceType = props.defaultCapacityInstance || DEFAULT_CAPACITY_TYPE; this.defaultCapacity = props.defaultCapacityType === DefaultCapacityType.EC2 ? @@ -1115,7 +1115,7 @@ export class Cluster extends ClusterBase { this.addNodegroupCapacity('DefaultCapacity', { instanceTypes: [instanceType], minSize: minCapacity }) : undefined; } - const outputConfigCommand = props.outputConfigCommand === undefined ? true : props.outputConfigCommand; + const outputConfigCommand = props.outputConfigCommand ?? true; if (outputConfigCommand) { const postfix = commonCommandOptions.join(' '); new CfnOutput(this, 'ConfigCommand', { value: `${updateConfigCommandPrefix} ${postfix}` }); @@ -1251,7 +1251,7 @@ export class Cluster extends ClusterBase { // allow traffic to/from managed node groups (eks attaches this security group to the managed nodes) autoScalingGroup.addSecurityGroup(this.clusterSecurityGroup); - const bootstrapEnabled = options.bootstrapEnabled !== undefined ? options.bootstrapEnabled : true; + const bootstrapEnabled = options.bootstrapEnabled ?? true; if (options.bootstrapOptions && !bootstrapEnabled) { throw new Error('Cannot specify "bootstrapOptions" if "bootstrapEnabled" is false'); } @@ -1278,7 +1278,7 @@ export class Cluster extends ClusterBase { // do not attempt to map the role if `kubectl` is not enabled for this // cluster or if `mapRole` is set to false. By default this should happen. - const mapRole = options.mapRole === undefined ? true : options.mapRole; + const mapRole = options.mapRole ?? true; if (mapRole) { // see https://docs.aws.amazon.com/en_us/eks/latest/userguide/add-user-role.html this.awsAuth.addRoleMapping(autoScalingGroup.role, { diff --git a/packages/@aws-cdk/aws-eks/lib/user-data.ts b/packages/@aws-cdk/aws-eks/lib/user-data.ts index cf38cf7ee9761..3b8d997535771 100644 --- a/packages/@aws-cdk/aws-eks/lib/user-data.ts +++ b/packages/@aws-cdk/aws-eks/lib/user-data.ts @@ -13,7 +13,7 @@ export function renderAmazonLinuxUserData(clusterName: string, autoScalingGroup: const extraArgs = new Array(); - extraArgs.push(`--use-max-pods ${options.useMaxPods === undefined ? true : options.useMaxPods}`); + extraArgs.push(`--use-max-pods ${options.useMaxPods ?? true}`); if (options.awsApiRetryAttempts) { extraArgs.push(`--aws-api-retry-attempts ${options.awsApiRetryAttempts}`); diff --git a/packages/@aws-cdk/aws-elasticloadbalancing/lib/load-balancer.ts b/packages/@aws-cdk/aws-elasticloadbalancing/lib/load-balancer.ts index 55c423f157a55..eaed2daee58d2 100644 --- a/packages/@aws-cdk/aws-elasticloadbalancing/lib/load-balancer.ts +++ b/packages/@aws-cdk/aws-elasticloadbalancing/lib/load-balancer.ts @@ -248,7 +248,7 @@ export class LoadBalancer extends Resource implements IConnectable { listeners: Lazy.any({ produce: () => this.listeners }), scheme: props.internetFacing ? 'internet-facing' : 'internal', healthCheck: props.healthCheck && healthCheckToJSON(props.healthCheck), - crossZone: (props.crossZone === undefined || props.crossZone) ? true : false, + crossZone: props.crossZone ?? true, }); if (props.internetFacing) { this.elb.node.addDependency(selectedSubnets.internetConnectivityEstablished); diff --git a/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/base-listener.ts b/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/base-listener.ts index 17170f4402b1a..db52671e5a368 100644 --- a/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/base-listener.ts +++ b/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/base-listener.ts @@ -108,7 +108,7 @@ export abstract class BaseListener extends Resource { const resource = new CfnListener(this, 'Resource', { ...additionalProps, - defaultActions: Lazy.any({ produce: () => this.defaultAction ? this.defaultAction.renderActions() : [] }), + defaultActions: Lazy.any({ produce: () => this.defaultAction?.renderActions() ?? [] }), }); this.listenerArn = resource.ref; diff --git a/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/base-target-group.ts b/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/base-target-group.ts index 0ff63805aab90..5e569fd8213ca 100644 --- a/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/base-target-group.ts +++ b/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/base-target-group.ts @@ -246,20 +246,20 @@ export abstract class TargetGroupBase extends CoreConstruct implements ITargetGr vpcId: cdk.Lazy.string({ produce: () => this.vpc && this.targetType !== TargetType.LAMBDA ? this.vpc.vpcId : undefined }), // HEALTH CHECK - healthCheckEnabled: cdk.Lazy.any({ produce: () => this.healthCheck && this.healthCheck.enabled }), + healthCheckEnabled: cdk.Lazy.any({ produce: () => this.healthCheck?.enabled }), healthCheckIntervalSeconds: cdk.Lazy.number({ - produce: () => this.healthCheck && this.healthCheck.interval && this.healthCheck.interval.toSeconds(), + produce: () => this.healthCheck?.interval?.toSeconds(), }), - healthCheckPath: cdk.Lazy.string({ produce: () => this.healthCheck && this.healthCheck.path }), - healthCheckPort: cdk.Lazy.string({ produce: () => this.healthCheck && this.healthCheck.port }), - healthCheckProtocol: cdk.Lazy.string({ produce: () => this.healthCheck && this.healthCheck.protocol }), + healthCheckPath: cdk.Lazy.string({ produce: () => this.healthCheck?.path }), + healthCheckPort: cdk.Lazy.string({ produce: () => this.healthCheck?.port }), + healthCheckProtocol: cdk.Lazy.string({ produce: () => this.healthCheck?.protocol }), healthCheckTimeoutSeconds: cdk.Lazy.number({ - produce: () => this.healthCheck && this.healthCheck.timeout && this.healthCheck.timeout.toSeconds(), + produce: () => this.healthCheck?.timeout?.toSeconds(), }), - healthyThresholdCount: cdk.Lazy.number({ produce: () => this.healthCheck && this.healthCheck.healthyThresholdCount }), - unhealthyThresholdCount: cdk.Lazy.number({ produce: () => this.healthCheck && this.healthCheck.unhealthyThresholdCount }), + healthyThresholdCount: cdk.Lazy.number({ produce: () => this.healthCheck?.healthyThresholdCount }), + unhealthyThresholdCount: cdk.Lazy.number({ produce: () => this.healthCheck?.unhealthyThresholdCount }), matcher: cdk.Lazy.any({ - produce: () => this.healthCheck && this.healthCheck.healthyHttpCodes !== undefined ? { + produce: () => this.healthCheck?.healthyHttpCodes !== undefined ? { httpCode: this.healthCheck.healthyHttpCodes, } : undefined, }), diff --git a/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/util.ts b/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/util.ts index 2ecc35c365694..a6d2692a59e83 100644 --- a/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/util.ts +++ b/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/util.ts @@ -67,7 +67,7 @@ export function determineProtocolAndPort(protocol: ApplicationProtocol | undefin * Helper function to default undefined input props */ export function ifUndefined(x: T | undefined, def: T) { - return x !== undefined ? x : def; + return x ?? def; } /** diff --git a/packages/@aws-cdk/aws-elasticloadbalancingv2/test/alb/security-group.test.ts b/packages/@aws-cdk/aws-elasticloadbalancingv2/test/alb/security-group.test.ts index e4d45eb609335..67d14cd4f721e 100644 --- a/packages/@aws-cdk/aws-elasticloadbalancingv2/test/alb/security-group.test.ts +++ b/packages/@aws-cdk/aws-elasticloadbalancingv2/test/alb/security-group.test.ts @@ -272,7 +272,7 @@ class TestFixture { }); this.lb = new elbv2.ApplicationLoadBalancer(this.stack, 'LB', { vpc: this.vpc }); - createListener = createListener === undefined ? true : createListener; + createListener = createListener ?? true; if (createListener) { this._listener = this.lb.addListener('Listener', { port: 80, open: false }); } diff --git a/packages/@aws-cdk/aws-events-targets/lib/ecs-task.ts b/packages/@aws-cdk/aws-events-targets/lib/ecs-task.ts index a4b19981dd0b1..baff4c76cde66 100644 --- a/packages/@aws-cdk/aws-events-targets/lib/ecs-task.ts +++ b/packages/@aws-cdk/aws-events-targets/lib/ecs-task.ts @@ -115,7 +115,7 @@ export class EcsTask implements events.IRuleTarget { this.cluster = props.cluster; this.taskDefinition = props.taskDefinition; - this.taskCount = props.taskCount !== undefined ? props.taskCount : 1; + this.taskCount = props.taskCount ?? 1; this.platformVersion = props.platformVersion; if (props.role) { diff --git a/packages/@aws-cdk/aws-events/lib/rule.ts b/packages/@aws-cdk/aws-events/lib/rule.ts index 0079954e73558..969965021f75d 100644 --- a/packages/@aws-cdk/aws-events/lib/rule.ts +++ b/packages/@aws-cdk/aws-events/lib/rule.ts @@ -166,7 +166,7 @@ export class Rule extends Resource implements IRule { const targetProps = target.bind(this, autoGeneratedId); const inputProps = targetProps.input && targetProps.input.bind(this); - const roleArn = targetProps.role ? targetProps.role.roleArn : undefined; + const roleArn = targetProps.role?.roleArn; const id = targetProps.id || autoGeneratedId; if (targetProps.targetResource) { @@ -298,7 +298,7 @@ export class Rule extends Resource implements IRule { sqsParameters: targetProps.sqsParameters, input: inputProps && inputProps.input, inputPath: inputProps && inputProps.inputPath, - inputTransformer: inputProps && inputProps.inputTemplate !== undefined ? { + inputTransformer: inputProps?.inputTemplate !== undefined ? { inputTemplate: inputProps.inputTemplate, inputPathsMap: inputProps.inputPathsMap, } : undefined, diff --git a/packages/@aws-cdk/aws-events/lib/schedule.ts b/packages/@aws-cdk/aws-events/lib/schedule.ts index 1e0a391e2b911..8c2c04481c0d2 100644 --- a/packages/@aws-cdk/aws-events/lib/schedule.ts +++ b/packages/@aws-cdk/aws-events/lib/schedule.ts @@ -115,7 +115,7 @@ class LiteralSchedule extends Schedule { } function fallback(x: T | undefined, def: T): T { - return x === undefined ? def : x; + return x ?? def; } /** diff --git a/packages/@aws-cdk/aws-glue/lib/table.ts b/packages/@aws-cdk/aws-glue/lib/table.ts index 859bb0b2ee325..635fe67a68d35 100644 --- a/packages/@aws-cdk/aws-glue/lib/table.ts +++ b/packages/@aws-cdk/aws-glue/lib/table.ts @@ -243,7 +243,7 @@ export class Table extends Resource implements ITable { this.columns = props.columns; this.partitionKeys = props.partitionKeys; - this.compressed = props.compressed === undefined ? false : props.compressed; + this.compressed = props.compressed ?? false; const { bucket, encryption, encryptionKey } = createBucket(this, props); this.bucket = bucket; this.encryption = encryption; @@ -267,7 +267,7 @@ export class Table extends Resource implements ITable { storageDescriptor: { location: `s3://${this.bucket.bucketName}/${this.s3Prefix}`, compressed: this.compressed, - storedAsSubDirectories: props.storedAsSubDirectories === undefined ? false : props.storedAsSubDirectories, + storedAsSubDirectories: props.storedAsSubDirectories ?? false, columns: renderColumns(props.columns), inputFormat: props.dataFormat.inputFormat.className, outputFormat: props.dataFormat.outputFormat.className, diff --git a/packages/@aws-cdk/aws-iam/lib/policy.ts b/packages/@aws-cdk/aws-iam/lib/policy.ts index 795049a1cc163..60862dca07c56 100644 --- a/packages/@aws-cdk/aws-iam/lib/policy.ts +++ b/packages/@aws-cdk/aws-iam/lib/policy.ts @@ -160,7 +160,7 @@ export class Policy extends Resource implements IPolicy { }); this._policyName = this.physicalName!; - this.force = props.force !== undefined ? props.force : false; + this.force = props.force ?? false; if (props.users) { props.users.forEach(u => this.attachToUser(u)); diff --git a/packages/@aws-cdk/aws-lambda/lib/event-invoke-config.ts b/packages/@aws-cdk/aws-lambda/lib/event-invoke-config.ts index 6c2419c6f8fd5..52e1021cd6878 100644 --- a/packages/@aws-cdk/aws-lambda/lib/event-invoke-config.ts +++ b/packages/@aws-cdk/aws-lambda/lib/event-invoke-config.ts @@ -90,7 +90,7 @@ export class EventInvokeConfig extends Resource { : undefined, functionName: props.function.functionName, maximumEventAgeInSeconds: props.maxEventAge && props.maxEventAge.toSeconds(), - maximumRetryAttempts: props.retryAttempts !== undefined ? props.retryAttempts : undefined, + maximumRetryAttempts: props.retryAttempts ?? undefined, qualifier: props.qualifier || '$LATEST', }); } diff --git a/packages/@aws-cdk/aws-logs/lib/metric-filter.ts b/packages/@aws-cdk/aws-logs/lib/metric-filter.ts index 8dda5f1728fd3..e9b076b55c8a3 100644 --- a/packages/@aws-cdk/aws-logs/lib/metric-filter.ts +++ b/packages/@aws-cdk/aws-logs/lib/metric-filter.ts @@ -42,7 +42,7 @@ export class MetricFilter extends Resource { metricTransformations: [{ metricNamespace: props.metricNamespace, metricName: props.metricName, - metricValue: props.metricValue !== undefined ? props.metricValue : '1', + metricValue: props.metricValue ?? '1', defaultValue: props.defaultValue, }], }); diff --git a/packages/@aws-cdk/aws-rds/lib/instance.ts b/packages/@aws-cdk/aws-rds/lib/instance.ts index 74a28666496d2..cb4c3d3487a8c 100644 --- a/packages/@aws-cdk/aws-rds/lib/instance.ts +++ b/packages/@aws-cdk/aws-rds/lib/instance.ts @@ -690,8 +690,8 @@ abstract class DatabaseInstanceNew extends DatabaseInstanceBase implements IData this.newCfnProps = { autoMinorVersionUpgrade: props.autoMinorVersionUpgrade, availabilityZone: props.multiAz ? undefined : props.availabilityZone, - backupRetentionPeriod: props.backupRetention ? props.backupRetention.toDays() : undefined, - copyTagsToSnapshot: props.copyTagsToSnapshot !== undefined ? props.copyTagsToSnapshot : true, + backupRetentionPeriod: props.backupRetention?.toDays(), + copyTagsToSnapshot: props.copyTagsToSnapshot ?? true, dbInstanceClass: Lazy.string({ produce: () => `db.${this.instanceType}` }), dbInstanceIdentifier: props.instanceIdentifier, dbSubnetGroupName: subnetGroup.subnetGroupName, @@ -701,15 +701,15 @@ abstract class DatabaseInstanceNew extends DatabaseInstanceBase implements IData enableIamDatabaseAuthentication: Lazy.any({ produce: () => this.enableIamAuthentication }), enablePerformanceInsights: enablePerformanceInsights || props.enablePerformanceInsights, // fall back to undefined if not set, iops, - monitoringInterval: props.monitoringInterval && props.monitoringInterval.toSeconds(), - monitoringRoleArn: monitoringRole && monitoringRole.roleArn, + monitoringInterval: props.monitoringInterval?.toSeconds(), + monitoringRoleArn: monitoringRole?.roleArn, multiAz: props.multiAz, optionGroupName: props.optionGroup?.optionGroupName, performanceInsightsKmsKeyId: props.performanceInsightEncryptionKey?.keyArn, performanceInsightsRetentionPeriod: enablePerformanceInsights ? (props.performanceInsightRetention || PerformanceInsightRetention.DEFAULT) : undefined, - port: props.port ? props.port.toString() : undefined, + port: props.port?.toString(), preferredBackupWindow: props.preferredBackupWindow, preferredMaintenanceWindow: props.preferredMaintenanceWindow, processorFeatures: props.processorFeatures && renderProcessorFeatures(props.processorFeatures), @@ -849,7 +849,7 @@ abstract class DatabaseInstanceSource extends DatabaseInstanceNew implements IDa ...this.newCfnProps, associatedRoles: instanceAssociatedRoles.length > 0 ? instanceAssociatedRoles : undefined, optionGroupName: engineConfig.optionGroup?.optionGroupName, - allocatedStorage: props.allocatedStorage ? props.allocatedStorage.toString() : '100', + allocatedStorage: props.allocatedStorage?.toString() ?? '100', allowMajorVersionUpgrade: props.allowMajorVersionUpgrade, dbName: props.databaseName, dbParameterGroupName: instanceParameterGroupConfig?.parameterGroupName, @@ -1041,9 +1041,7 @@ export class DatabaseInstanceFromSnapshot extends DatabaseInstanceSource impleme const instance = new CfnDBInstance(this, 'Resource', { ...this.sourceCfnProps, dbSnapshotIdentifier: props.snapshotIdentifier, - masterUserPassword: secret - ? secret.secretValueFromJson('password').toString() - : credentials?.password?.toString(), + masterUserPassword: secret?.secretValueFromJson('password')?.toString() ?? credentials?.password?.toString(), }); this.instanceIdentifier = instance.ref; @@ -1117,7 +1115,7 @@ export class DatabaseInstanceReadReplica extends DatabaseInstanceNew implements ...this.newCfnProps, // this must be ARN, not ID, because of https://github.com/terraform-providers/terraform-provider-aws/issues/528#issuecomment-391169012 sourceDbInstanceIdentifier: props.sourceDatabaseInstance.instanceArn, - kmsKeyId: props.storageEncryptionKey && props.storageEncryptionKey.keyArn, + kmsKeyId: props.storageEncryptionKey?.keyArn, storageEncrypted: props.storageEncryptionKey ? true : props.storageEncrypted, }); diff --git a/packages/@aws-cdk/aws-rds/lib/private/util.ts b/packages/@aws-cdk/aws-rds/lib/private/util.ts index ca5f16d21e038..f97486b5daddf 100644 --- a/packages/@aws-cdk/aws-rds/lib/private/util.ts +++ b/packages/@aws-cdk/aws-rds/lib/private/util.ts @@ -92,9 +92,7 @@ export function applyRemovalPolicy(cfnDatabase: CfnResource, removalPolicy?: Rem * Enable if explicitly provided or if the RemovalPolicy has been set to RETAIN */ export function defaultDeletionProtection(deletionProtection?: boolean, removalPolicy?: RemovalPolicy): boolean | undefined { - return deletionProtection !== undefined - ? deletionProtection - : (removalPolicy === RemovalPolicy.RETAIN ? true : undefined); + return deletionProtection ?? (removalPolicy === RemovalPolicy.RETAIN ? true : undefined); } /** diff --git a/packages/@aws-cdk/aws-redshift/lib/cluster.ts b/packages/@aws-cdk/aws-redshift/lib/cluster.ts index 9126ef4fda737..0add37fbbdff3 100644 --- a/packages/@aws-cdk/aws-redshift/lib/cluster.ts +++ b/packages/@aws-cdk/aws-redshift/lib/cluster.ts @@ -406,11 +406,11 @@ export class Cluster extends ClusterBase { super(scope, id); this.vpc = props.vpc; - this.vpcSubnets = props.vpcSubnets ? props.vpcSubnets : { + this.vpcSubnets = props.vpcSubnets ?? { subnetType: ec2.SubnetType.PRIVATE, }; - const removalPolicy = props.removalPolicy ? props.removalPolicy : RemovalPolicy.RETAIN; + const removalPolicy = props.removalPolicy ?? RemovalPolicy.RETAIN; const subnetGroup = props.subnetGroup ?? new ClusterSubnetGroup(this, 'Subnets', { description: `Subnets for ${id} Redshift cluster`, @@ -419,11 +419,10 @@ export class Cluster extends ClusterBase { removalPolicy: removalPolicy, }); - const securityGroups = props.securityGroups !== undefined ? - props.securityGroups : [new ec2.SecurityGroup(this, 'SecurityGroup', { - description: 'Redshift security group', - vpc: this.vpc, - })]; + const securityGroups = props.securityGroups ?? [new ec2.SecurityGroup(this, 'SecurityGroup', { + description: 'Redshift security group', + vpc: this.vpc, + })]; const securityGroupIds = securityGroups.map(sg => sg.securityGroupId); @@ -464,22 +463,20 @@ export class Cluster extends ClusterBase { port: props.port, clusterParameterGroupName: props.parameterGroup && props.parameterGroup.clusterParameterGroupName, // Admin - masterUsername: secret ? secret.secretValueFromJson('username').toString() : props.masterUser.masterUsername, - masterUserPassword: secret - ? secret.secretValueFromJson('password').toString() - : (props.masterUser.masterPassword - ? props.masterUser.masterPassword.toString() - : 'default'), + masterUsername: secret?.secretValueFromJson('username').toString() ?? props.masterUser.masterUsername, + masterUserPassword: secret?.secretValueFromJson('password').toString() + ?? props.masterUser.masterPassword?.toString() + ?? 'default', preferredMaintenanceWindow: props.preferredMaintenanceWindow, nodeType: props.nodeType || NodeType.DC2_LARGE, numberOfNodes: nodeCount, loggingProperties, - iamRoles: props.roles ? props.roles.map(role => role.roleArn) : undefined, + iamRoles: props?.roles?.map(role => role.roleArn), dbName: props.defaultDatabaseName || 'default_db', publiclyAccessible: props.publiclyAccessible || false, // Encryption kmsKeyId: props.encryptionKey && props.encryptionKey.keyArn, - encrypted: props.encrypted !== undefined ? props.encrypted : true, + encrypted: props.encrypted ?? true, }); cluster.applyRemovalPolicy(removalPolicy, { diff --git a/packages/@aws-cdk/aws-s3-deployment/lib/bucket-deployment.ts b/packages/@aws-cdk/aws-s3-deployment/lib/bucket-deployment.ts index bbf526b79df86..4ca33864952f3 100644 --- a/packages/@aws-cdk/aws-s3-deployment/lib/bucket-deployment.ts +++ b/packages/@aws-cdk/aws-s3-deployment/lib/bucket-deployment.ts @@ -227,7 +227,7 @@ export class BucketDeployment extends CoreConstruct { Prune: props.prune ?? true, UserMetadata: props.metadata ? mapUserMetadata(props.metadata) : undefined, SystemMetadata: mapSystemMetadata(props), - DistributionId: props.distribution ? props.distribution.distributionId : undefined, + DistributionId: props.distribution?.distributionId, DistributionPaths: props.distributionPaths, }, }); diff --git a/packages/@aws-cdk/aws-s3/lib/bucket.ts b/packages/@aws-cdk/aws-s3/lib/bucket.ts index 5c5abfbfec559..525b22f6afd1d 100644 --- a/packages/@aws-cdk/aws-s3/lib/bucket.ts +++ b/packages/@aws-cdk/aws-s3/lib/bucket.ts @@ -413,7 +413,7 @@ abstract class BucketBase extends Resource implements IBucket { detailType: ['AWS API Call via CloudTrail'], detail: { resources: { - ARN: options.paths ? options.paths.map(p => this.arnForObjects(p)) : [this.bucketArn], + ARN: options.paths?.map(p => this.arnForObjects(p)) ?? [this.bucketArn], }, }, }); @@ -1607,13 +1607,13 @@ export class Bucket extends BucketBase { return { rules: this.lifecycleRules.map(parseLifecycleRule) }; function parseLifecycleRule(rule: LifecycleRule): CfnBucket.RuleProperty { - const enabled = rule.enabled !== undefined ? rule.enabled : true; + const enabled = rule.enabled ?? true; const x: CfnBucket.RuleProperty = { // eslint-disable-next-line max-len abortIncompleteMultipartUpload: rule.abortIncompleteMultipartUploadAfter !== undefined ? { daysAfterInitiation: rule.abortIncompleteMultipartUploadAfter.toDays() } : undefined, expirationDate: rule.expirationDate, - expirationInDays: rule.expiration && rule.expiration.toDays(), + expirationInDays: rule.expiration?.toDays(), id: rule.id, noncurrentVersionExpirationInDays: rule.noncurrentVersionExpiration && rule.noncurrentVersionExpiration.toDays(), noncurrentVersionTransitions: mapOrUndefined(rule.noncurrentVersionTransitions, t => ({ diff --git a/packages/@aws-cdk/aws-ses-actions/lib/bounce.ts b/packages/@aws-cdk/aws-ses-actions/lib/bounce.ts index b84c414c5c43e..a1a385651614a 100644 --- a/packages/@aws-cdk/aws-ses-actions/lib/bounce.ts +++ b/packages/@aws-cdk/aws-ses-actions/lib/bounce.ts @@ -100,7 +100,7 @@ export class Bounce implements ses.IReceiptRuleAction { sender: this.props.sender, smtpReplyCode: this.props.template.props.smtpReplyCode, message: this.props.template.props.message, - topicArn: this.props.topic ? this.props.topic.topicArn : undefined, + topicArn: this.props.topic?.topicArn, statusCode: this.props.template.props.statusCode, }, }; diff --git a/packages/@aws-cdk/aws-ses-actions/lib/lambda.ts b/packages/@aws-cdk/aws-ses-actions/lib/lambda.ts index 290211bf1806f..d6be68f92ce24 100644 --- a/packages/@aws-cdk/aws-ses-actions/lib/lambda.ts +++ b/packages/@aws-cdk/aws-ses-actions/lib/lambda.ts @@ -78,7 +78,7 @@ export class Lambda implements ses.IReceiptRuleAction { lambdaAction: { functionArn: this.props.function.functionArn, invocationType: this.props.invocationType, - topicArn: this.props.topic ? this.props.topic.topicArn : undefined, + topicArn: this.props.topic?.topicArn, }, }; } diff --git a/packages/@aws-cdk/aws-ses-actions/lib/s3.ts b/packages/@aws-cdk/aws-ses-actions/lib/s3.ts index 9be2fd8750378..1f288afe2a887 100644 --- a/packages/@aws-cdk/aws-ses-actions/lib/s3.ts +++ b/packages/@aws-cdk/aws-ses-actions/lib/s3.ts @@ -92,9 +92,9 @@ export class S3 implements ses.IReceiptRuleAction { return { s3Action: { bucketName: this.props.bucket.bucketName, - kmsKeyArn: this.props.kmsKey ? this.props.kmsKey.keyArn : undefined, + kmsKeyArn: this.props.kmsKey?.keyArn, objectKeyPrefix: this.props.objectKeyPrefix, - topicArn: this.props.topic ? this.props.topic.topicArn : undefined, + topicArn: this.props.topic?.topicArn, }, }; } diff --git a/packages/@aws-cdk/aws-ses-actions/lib/stop.ts b/packages/@aws-cdk/aws-ses-actions/lib/stop.ts index ab2e9cbb91d1e..f42d206d3d350 100644 --- a/packages/@aws-cdk/aws-ses-actions/lib/stop.ts +++ b/packages/@aws-cdk/aws-ses-actions/lib/stop.ts @@ -23,7 +23,7 @@ export class Stop implements ses.IReceiptRuleAction { return { stopAction: { scope: 'RuleSet', - topicArn: this.props.topic ? this.props.topic.topicArn : undefined, + topicArn: this.props.topic?.topicArn, }, }; } diff --git a/packages/@aws-cdk/aws-ses/lib/receipt-rule-set.ts b/packages/@aws-cdk/aws-ses/lib/receipt-rule-set.ts index c94d4d4edd138..dcb3d011d4251 100644 --- a/packages/@aws-cdk/aws-ses/lib/receipt-rule-set.ts +++ b/packages/@aws-cdk/aws-ses/lib/receipt-rule-set.ts @@ -62,7 +62,7 @@ abstract class ReceiptRuleSetBase extends Resource implements IReceiptRuleSet { */ public addRule(id: string, options?: ReceiptRuleOptions): ReceiptRule { this.lastAddedRule = new ReceiptRule(this, id, { - after: this.lastAddedRule ? this.lastAddedRule : undefined, + after: this.lastAddedRule ?? undefined, ruleSet: this, ...options, }); diff --git a/packages/@aws-cdk/aws-ses/lib/receipt-rule.ts b/packages/@aws-cdk/aws-ses/lib/receipt-rule.ts index 72c056d913693..5b6a276929c8e 100644 --- a/packages/@aws-cdk/aws-ses/lib/receipt-rule.ts +++ b/packages/@aws-cdk/aws-ses/lib/receipt-rule.ts @@ -124,10 +124,10 @@ export class ReceiptRule extends Resource implements IReceiptRule { }); const resource = new CfnReceiptRule(this, 'Resource', { - after: props.after ? props.after.receiptRuleName : undefined, + after: props.after?.receiptRuleName, rule: { actions: Lazy.any({ produce: () => this.renderActions() }), - enabled: props.enabled === undefined ? true : props.enabled, + enabled: props.enabled ?? true, name: this.physicalName, recipients: props.recipients, scanEnabled: props.scanEnabled, diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/lib/emr/emr-create-cluster.ts b/packages/@aws-cdk/aws-stepfunctions-tasks/lib/emr/emr-create-cluster.ts index 4b3ecd5ca0013..2e38d60aac150 100644 --- a/packages/@aws-cdk/aws-stepfunctions-tasks/lib/emr/emr-create-cluster.ts +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/lib/emr/emr-create-cluster.ts @@ -173,7 +173,7 @@ export class EmrCreateCluster extends sfn.TaskStateBase { constructor(scope: Construct, id: string, private readonly props: EmrCreateClusterProps) { super(scope, id, props); - this.visibleToAllUsers = this.props.visibleToAllUsers !== undefined ? this.props.visibleToAllUsers : true; + this.visibleToAllUsers = this.props.visibleToAllUsers ?? true; this.integrationPattern = props.integrationPattern || sfn.IntegrationPattern.RUN_JOB; validatePatternSupported(this.integrationPattern, EmrCreateCluster.SUPPORTED_INTEGRATION_PATTERNS); diff --git a/packages/@aws-cdk/aws-stepfunctions/lib/state-machine.ts b/packages/@aws-cdk/aws-stepfunctions/lib/state-machine.ts index 56b14e69fa5d8..8c7ee585e4b09 100644 --- a/packages/@aws-cdk/aws-stepfunctions/lib/state-machine.ts +++ b/packages/@aws-cdk/aws-stepfunctions/lib/state-machine.ts @@ -380,11 +380,11 @@ export class StateMachine extends StateMachineBase { const graph = new StateGraph(props.definition.startState, `State Machine ${id} definition`); graph.timeout = props.timeout; - this.stateMachineType = props.stateMachineType ? props.stateMachineType : StateMachineType.STANDARD; + this.stateMachineType = props.stateMachineType ?? StateMachineType.STANDARD; const resource = new CfnStateMachine(this, 'Resource', { stateMachineName: this.physicalName, - stateMachineType: props.stateMachineType ? props.stateMachineType : undefined, + stateMachineType: props.stateMachineType ?? undefined, roleArn: this.role.roleArn, definitionString: Stack.of(this).toJsonString(graph.toGraphJson()), loggingConfiguration: props.logs ? this.buildLoggingConfiguration(props.logs) : undefined, diff --git a/packages/@aws-cdk/aws-stepfunctions/lib/states/pass.ts b/packages/@aws-cdk/aws-stepfunctions/lib/states/pass.ts index de9b4d16aab01..fb5e52d2831b2 100644 --- a/packages/@aws-cdk/aws-stepfunctions/lib/states/pass.ts +++ b/packages/@aws-cdk/aws-stepfunctions/lib/states/pass.ts @@ -145,7 +145,7 @@ export class Pass extends State implements INextable { return { Type: StateType.PASS, Comment: this.comment, - Result: this.result ? this.result.value : undefined, + Result: this.result?.value, ResultPath: renderJsonPath(this.resultPath), ...this.renderInputOutput(), ...this.renderParameters(), diff --git a/packages/@aws-cdk/aws-stepfunctions/lib/states/state.ts b/packages/@aws-cdk/aws-stepfunctions/lib/states/state.ts index 02cceb6e64ed2..42a4c8e9bf1b5 100644 --- a/packages/@aws-cdk/aws-stepfunctions/lib/states/state.ts +++ b/packages/@aws-cdk/aws-stepfunctions/lib/states/state.ts @@ -254,7 +254,7 @@ export abstract class State extends CoreConstruct implements IChainable { this.retries.push({ ...props, - errors: props.errors ? props.errors : [Errors.ALL], + errors: props.errors ?? [Errors.ALL], }); } @@ -268,7 +268,7 @@ export abstract class State extends CoreConstruct implements IChainable { this.catches.push({ next: handler, props: { - errors: props.errors ? props.errors : [Errors.ALL], + errors: props.errors ?? [Errors.ALL], resultPath: props.resultPath, }, }); @@ -352,7 +352,7 @@ export abstract class State extends CoreConstruct implements IChainable { protected renderChoices(): any { return { Choices: renderList(this.choices, renderChoice), - Default: this.defaultChoice ? this.defaultChoice.stateId : undefined, + Default: this.defaultChoice?.stateId, }; } diff --git a/packages/@aws-cdk/core/lib/app.ts b/packages/@aws-cdk/core/lib/app.ts index eb095f801ee4f..28e04607a0228 100644 --- a/packages/@aws-cdk/core/lib/app.ts +++ b/packages/@aws-cdk/core/lib/app.ts @@ -116,7 +116,7 @@ export class App extends Stage { this.node.setContext(cxapi.ANALYTICS_REPORTING_ENABLED_CONTEXT, analyticsReporting); } - const autoSynth = props.autoSynth !== undefined ? props.autoSynth : cxapi.OUTDIR_ENV in process.env; + const autoSynth = props.autoSynth ?? cxapi.OUTDIR_ENV in process.env; if (autoSynth) { // synth() guarantuees it will only execute once, so a default of 'true' // doesn't bite manual calling of the function. diff --git a/packages/@aws-cdk/core/lib/arn.ts b/packages/@aws-cdk/core/lib/arn.ts index 2ed3485a6c9b6..1ffcc2da2b33c 100644 --- a/packages/@aws-cdk/core/lib/arn.ts +++ b/packages/@aws-cdk/core/lib/arn.ts @@ -77,10 +77,10 @@ export class Arn { * can be 'undefined'. */ public static format(components: ArnComponents, stack: Stack): string { - const partition = components.partition !== undefined ? components.partition : stack.partition; - const region = components.region !== undefined ? components.region : stack.region; - const account = components.account !== undefined ? components.account : stack.account; - const sep = components.sep !== undefined ? components.sep : '/'; + const partition = components.partition ?? stack.partition; + const region = components.region ?? stack.region; + const account = components.account ?? stack.account; + const sep = components.sep ?? '/'; const values = ['arn', ':', partition, ':', components.service, ':', region, ':', account, ':', components.resource]; diff --git a/packages/@aws-cdk/core/lib/fs/copy.ts b/packages/@aws-cdk/core/lib/fs/copy.ts index b9feb555c8f65..627dc2aa988dc 100644 --- a/packages/@aws-cdk/core/lib/fs/copy.ts +++ b/packages/@aws-cdk/core/lib/fs/copy.ts @@ -5,7 +5,7 @@ import { CopyOptions, SymlinkFollowMode } from './options'; import { shouldFollow } from './utils'; export function copyDirectory(srcDir: string, destDir: string, options: CopyOptions = { }, rootDir?: string) { - const follow = options.follow !== undefined ? options.follow : SymlinkFollowMode.EXTERNAL; + const follow = options.follow ?? SymlinkFollowMode.EXTERNAL; rootDir = rootDir || srcDir; diff --git a/packages/@aws-cdk/core/lib/stack.ts b/packages/@aws-cdk/core/lib/stack.ts index 53e7adfdc206e..2284ddedc203f 100644 --- a/packages/@aws-cdk/core/lib/stack.ts +++ b/packages/@aws-cdk/core/lib/stack.ts @@ -371,7 +371,7 @@ export class Stack extends CoreConstruct implements ITaggable { this.templateOptions.description = props.description; } - this._stackName = props.stackName !== undefined ? props.stackName : this.generateStackName(); + this._stackName = props.stackName ?? this.generateStackName(); this.tags = new TagManager(TagType.KEY_VALUE, 'aws:cdk:stack', props.tags); if (!VALID_STACK_NAME_REGEX.test(this.stackName)) { diff --git a/packages/@aws-cdk/core/lib/tag-aspect.ts b/packages/@aws-cdk/core/lib/tag-aspect.ts index d56c28b551d87..09d79c7ea9799 100644 --- a/packages/@aws-cdk/core/lib/tag-aspect.ts +++ b/packages/@aws-cdk/core/lib/tag-aspect.ts @@ -126,7 +126,7 @@ export class Tag extends TagBase { resource.tags.setTag( this.key, this.value, - this.props.priority !== undefined ? this.props.priority : this.defaultPriority, + this.props.priority ?? this.defaultPriority, this.props.applyToLaunchedInstances !== false, ); } @@ -175,7 +175,7 @@ export class RemoveTag extends TagBase { protected applyTag(resource: ITaggable): void { if (resource.tags.applyTagAspectHere(this.props.includeResourceTypes, this.props.excludeResourceTypes)) { - resource.tags.removeTag(this.key, this.props.priority !== undefined ? this.props.priority : this.defaultPriority); + resource.tags.removeTag(this.key, this.props.priority ?? this.defaultPriority); } } } diff --git a/packages/@aws-cdk/core/lib/token.ts b/packages/@aws-cdk/core/lib/token.ts index 4bbcdb454f9bd..f92a2560cac7c 100644 --- a/packages/@aws-cdk/core/lib/token.ts +++ b/packages/@aws-cdk/core/lib/token.ts @@ -183,7 +183,7 @@ export class Tokenization { return resolve(obj, { scope: options.scope, resolver: options.resolver, - preparing: (options.preparing !== undefined ? options.preparing : false), + preparing: (options.preparing ?? false), }); } diff --git a/packages/@aws-cdk/core/test/tag-aspect.test.ts b/packages/@aws-cdk/core/test/tag-aspect.test.ts index cb2c5363e2153..b0871e2d13c02 100644 --- a/packages/@aws-cdk/core/test/tag-aspect.test.ts +++ b/packages/@aws-cdk/core/test/tag-aspect.test.ts @@ -6,7 +6,7 @@ class TaggableResource extends CfnResource { public readonly tags: TagManager; constructor(scope: Construct, id: string, props: CfnResourceProps) { super(scope, id, props); - const tags = props.properties === undefined ? undefined : props.properties.tags; + const tags = props.properties?.tags; this.tags = new TagManager(TagType.STANDARD, 'AWS::Fake::Resource', tags); } public testProperties() { @@ -18,7 +18,7 @@ class AsgTaggableResource extends CfnResource { public readonly tags: TagManager; constructor(scope: Construct, id: string, props: CfnResourceProps) { super(scope, id, props); - const tags = props.properties === undefined ? undefined : props.properties.tags; + const tags = props.properties?.tags; this.tags = new TagManager(TagType.AUTOSCALING_GROUP, 'AWS::Fake::Resource', tags); } public testProperties() { @@ -30,7 +30,7 @@ class MapTaggableResource extends CfnResource { public readonly tags: TagManager; constructor(scope: Construct, id: string, props: CfnResourceProps) { super(scope, id, props); - const tags = props.properties === undefined ? undefined : props.properties.tags; + const tags = props.properties?.tags; this.tags = new TagManager(TagType.MAP, 'AWS::Fake::Resource', tags); } public testProperties() { diff --git a/packages/aws-cdk/lib/cdk-toolkit.ts b/packages/aws-cdk/lib/cdk-toolkit.ts index c3e8c649eaa7b..84542eb8f4c7f 100644 --- a/packages/aws-cdk/lib/cdk-toolkit.ts +++ b/packages/aws-cdk/lib/cdk-toolkit.ts @@ -110,7 +110,7 @@ export class CdkToolkit { public async deploy(options: DeployOptions) { const stacks = await this.selectStacksForDeploy(options.stackNames, options.exclusively); - const requireApproval = options.requireApproval !== undefined ? options.requireApproval : RequireApproval.Broadening; + const requireApproval = options.requireApproval ?? RequireApproval.Broadening; const parameterMap: { [name: string]: { [name: string]: string | undefined } } = { '*': {} }; for (const key in options.parameters) {