Skip to content

Commit

Permalink
Do not use spread syntax on accumulators (#897)
Browse files Browse the repository at this point in the history
  • Loading branch information
trivikr authored Jul 12, 2024
1 parent e66c64b commit 8a1fdff
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 42 deletions.
5 changes: 5 additions & 0 deletions .changeset/gentle-news-provide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"aws-sdk-js-codemod": patch
---

Do not use spread syntax on accumulators
3 changes: 0 additions & 3 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@
"noUndeclaredVariables": "error",
"noUnusedVariables": "error"
},
"performance": {
"noAccumulatingSpread": "off"
},
"style": {
"noNamespace": "error",
"noNonNullAssertion": "off",
Expand Down
17 changes: 10 additions & 7 deletions src/transforms/v2-to-v3/client-names/getClientMetadataRecord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,19 @@ export const getClientMetadataRecord = (
): ClientMetadataRecord =>
Object.entries(
Object.entries(v2ClientNamesRecord).reduce(
(acc, [v2ClientName, v2ClientLocalName]) => ({
...acc,
[v2ClientName]: {
(acc: ClientMetadataRecord, [v2ClientName, v2ClientLocalName]) => {
acc[v2ClientName] = {
v2ClientLocalName,
v3ClientName: getV3ClientName(v2ClientName),
v3ClientPackageName: getV3ClientPackageName(v2ClientName),
},
}),
};
return acc;
},
{}
) as ClientMetadataRecord
)
)
.sort(([, { v3ClientPackageName: a }], [, { v3ClientPackageName: b }]) => b.localeCompare(a))
.reduce((r, [k, v]) => ({ ...r, [k]: v }), {});
.reduce((acc: ClientMetadataRecord, [key, value]) => {
acc[key] = value;
return acc;
}, {});
5 changes: 4 additions & 1 deletion src/transforms/v2-to-v3/config/CLIENT_NAMES_MAP.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import { CLIENT_NAMES } from "./CLIENT_NAMES";

// The key is the client name in v2, and value is the client name in v3.
export const CLIENT_NAMES_MAP: Record<string, string> = {
...CLIENT_NAMES.reduce((acc, name) => ({ ...acc, [name]: name }), {}),
...CLIENT_NAMES.reduce((acc: Record<string, string>, name) => {
acc[name] = name;
return acc;
}, {}),
AugmentedAIRuntime: "SageMakerA2IRuntime",
CUR: "CostAndUsageReportService",
CodeArtifact: "Codeartifact",
Expand Down
59 changes: 28 additions & 31 deletions src/transforms/v2-to-v3/config/CLIENT_PACKAGE_NAMES_MAP.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,34 @@ import { CLIENT_NAMES } from "./CLIENT_NAMES";

// The key is the client name in v2, and value is the client package name in v3.
export const CLIENT_PACKAGE_NAMES_MAP: Record<string, string> = {
...CLIENT_NAMES.reduce(
(acc, name) => ({
...acc,
[name]: `client-${name.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase()}`
.replace("-chime-sdk", "-chime-sdk-")
.replace("client-amplify-", "client-amplify")
.replace("client-bcmdata-exports", "client-bcm-data-exports")
.replace("client-control-catalog", "client-controlcatalog")
.replace("client-clean-rooms-ml", "client-cleanroomsml")
.replace("client-cloud-", "client-cloud")
.replace("client-code-", "client-code")
.replace("client-connect-", "client-connect")
.replace("client-data-", "client-data")
.replace("client-free-tier", "client-freetier")
.replace("client-io-t", "client-iot-")
.replace("client-iot-fleet-", "client-iotfleet")
.replace("client-lookout-", "client-lookout")
.replace("client-media-", "client-media")
.replace("client-migration-hub-", "client-migrationhub")
.replace("client-network-monitor", "client-networkmonitor")
.replace("client-pinpoint-sms", "client-pinpoint-sms-")
.replace("client-route53", "client-route53-")
.replace("client-sage-maker", "client-sagemaker")
.replace("client-security-", "client-security")
.replace("client-supply-chain", "client-supplychain")
.replace("client-timestream-influx-db", "client-timestream-influxdb")
.replace("client-trusted-advisor", "client-trustedadvisor")
.replace("client-work-", "client-work"),
}),
{}
),
...CLIENT_NAMES.reduce((acc: Record<string, string>, name) => {
acc[name] = `client-${name.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase()}`
.replace("-chime-sdk", "-chime-sdk-")
.replace("client-amplify-", "client-amplify")
.replace("client-bcmdata-exports", "client-bcm-data-exports")
.replace("client-control-catalog", "client-controlcatalog")
.replace("client-clean-rooms-ml", "client-cleanroomsml")
.replace("client-cloud-", "client-cloud")
.replace("client-code-", "client-code")
.replace("client-connect-", "client-connect")
.replace("client-data-", "client-data")
.replace("client-free-tier", "client-freetier")
.replace("client-io-t", "client-iot-")
.replace("client-iot-fleet-", "client-iotfleet")
.replace("client-lookout-", "client-lookout")
.replace("client-media-", "client-media")
.replace("client-migration-hub-", "client-migrationhub")
.replace("client-network-monitor", "client-networkmonitor")
.replace("client-pinpoint-sms", "client-pinpoint-sms-")
.replace("client-route53", "client-route53-")
.replace("client-sage-maker", "client-sagemaker")
.replace("client-security-", "client-security")
.replace("client-supply-chain", "client-supplychain")
.replace("client-timestream-influx-db", "client-timestream-influxdb")
.replace("client-trusted-advisor", "client-trustedadvisor")
.replace("client-work-", "client-work");
return acc;
}, {}),
AccessAnalyzer: "client-accessanalyzer",
ACMPCA: "client-acm-pca",
APIGateway: "client-api-gateway",
Expand Down

0 comments on commit 8a1fdff

Please sign in to comment.