Skip to content

Commit b4b12b3

Browse files
authored
Use formatting convention of trailing comma from input code (#713)
1 parent 3d1dd7f commit b4b12b3

35 files changed

+65
-35
lines changed

.changeset/calm-goats-try.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"aws-sdk-js-codemod": patch
3+
---
4+
5+
Use formatting convention of trailing comma from input code

src/transforms/v2-to-v3/__fixtures__/config/credentials.order.input.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ const credsBefore = new AWS.Config({
1111
accessKeyId: "KEY",
1212
secretAccessKey: "SECRET",
1313
logger: console,
14-
region: "us-east-1",
14+
region: "us-east-1"
1515
});
1616

1717
const credsInBetween = new AWS.Config({
1818
logger: console,
1919
accessKeyId: "KEY",
2020
secretAccessKey: "SECRET",
21-
region: "us-east-1",
21+
region: "us-east-1"
2222
});
2323

2424
const credsDispersedBefore = new AWS.Config({
@@ -32,5 +32,5 @@ const credsDispersedAfter = new AWS.Config({
3232
logger: console,
3333
accessKeyId: "KEY",
3434
region: "us-east-1",
35-
secretAccessKey: "SECRET",
35+
secretAccessKey: "SECRET"
3636
});

src/transforms/v2-to-v3/__fixtures__/config/httpOptions.input.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ import AWS from "aws-sdk";
22

33
const config = new AWS.Config({
44
httpOptions: {
5-
connectTimeout: 1000,
5+
connectTimeout: 1000
66
}
77
});

src/transforms/v2-to-v3/__fixtures__/config/httpOptions.output.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ const config = {
33
// Refer to UPGRADING.md on aws-sdk-js-v3 for changes needed.
44
// Please create/upvote feature request on aws-sdk-js-codemod for httpOptions.
55
httpOptions: {
6-
connectTimeout: 1000,
6+
connectTimeout: 1000
77
}
88
};
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import AWS from "aws-sdk";
22

33
const documentClient = new AWS.DynamoDB.DocumentClient({
4-
convertEmptyValues: true,
4+
convertEmptyValues: true
55
});
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import AWS from "aws-sdk";
22

33
const documentClient = new AWS.DynamoDB.DocumentClient({
4-
wrapNumbers: true,
4+
wrapNumbers: true
55
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import AWS from "aws-sdk";
2+
3+
const client = new AWS.DynamoDB({
4+
region: "us-west-2",
5+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { DynamoDB } from "@aws-sdk/client-dynamodb";
2+
3+
const client = new DynamoDB({
4+
region: "us-west-2",
5+
});

src/transforms/v2-to-v3/__fixtures__/s3-upload/global-import-equals.input.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ await client.upload({
55
Body: "BODY",
66
Bucket: "Bucket",
77
ContentType: "ContentType",
8-
Key: "Key",
8+
Key: "Key"
99
}).promise();

src/transforms/v2-to-v3/__fixtures__/s3-upload/global-import-equals.output.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ await new Upload({
1111
Body: "BODY",
1212
Bucket: "Bucket",
1313
ContentType: "ContentType",
14-
Key: "Key",
14+
Key: "Key"
1515
}
1616
}).done();

src/transforms/v2-to-v3/__fixtures__/s3-upload/global-import.input.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ await client.upload({
55
Body: "BODY",
66
Bucket: "Bucket",
77
ContentType: "ContentType",
8-
Key: "Key",
8+
Key: "Key"
99
}).promise();

src/transforms/v2-to-v3/__fixtures__/s3-upload/global-import.output.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ await new Upload({
99
Body: "BODY",
1010
Bucket: "Bucket",
1111
ContentType: "ContentType",
12-
Key: "Key",
12+
Key: "Key"
1313
}
1414
}).done();

src/transforms/v2-to-v3/__fixtures__/s3-upload/global-require-property.input.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ await client.upload({
55
Body: "BODY",
66
Bucket: "Bucket",
77
ContentType: "ContentType",
8-
Key: "Key",
8+
Key: "Key"
99
}).promise();

src/transforms/v2-to-v3/__fixtures__/s3-upload/global-require-property.output.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ await new Upload({
1414
Body: "BODY",
1515
Bucket: "Bucket",
1616
ContentType: "ContentType",
17-
Key: "Key",
17+
Key: "Key"
1818
}
1919
}).done();

src/transforms/v2-to-v3/__fixtures__/s3-upload/global-require.input.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ await client.upload({
55
Body: "BODY",
66
Bucket: "Bucket",
77
ContentType: "ContentType",
8-
Key: "Key",
8+
Key: "Key"
99
}).promise();

src/transforms/v2-to-v3/__fixtures__/s3-upload/global-require.output.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ await new Upload({
1414
Body: "BODY",
1515
Bucket: "Bucket",
1616
ContentType: "ContentType",
17-
Key: "Key",
17+
Key: "Key"
1818
}
1919
}).done();

src/transforms/v2-to-v3/__fixtures__/s3-upload/options-identifier.input.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ const uploadParams = {
66
Body: "BODY",
77
Bucket: "Bucket",
88
ContentType: "ContentType",
9-
Key: "Key",
9+
Key: "Key"
1010
};
1111
const uploadOptions = {
1212
partSize: 1024 * 1024 * 5,
1313
queueSize: 1,
1414
leavePartsOnError: true,
15-
tags: [],
15+
tags: []
1616
};
1717

1818
await client.upload(uploadParams, uploadOptions).promise();

src/transforms/v2-to-v3/__fixtures__/s3-upload/options-identifier.output.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ const uploadParams = {
77
Body: "BODY",
88
Bucket: "Bucket",
99
ContentType: "ContentType",
10-
Key: "Key",
10+
Key: "Key"
1111
};
1212
const uploadOptions = {
1313
partSize: 1024 * 1024 * 5,
1414
queueSize: 1,
1515
leavePartsOnError: true,
16-
tags: [],
16+
tags: []
1717
};
1818

1919
await new Upload({

src/transforms/v2-to-v3/__fixtures__/s3-upload/options.input.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ await client
77
Body: "BODY",
88
Bucket: "Bucket",
99
ContentType: "ContentType",
10-
Key: "Key",
10+
Key: "Key"
1111
},
1212
{
1313
partSize: 1024 * 1024 * 5,
1414
queueSize: 1,
1515
leavePartsOnError: true,
16-
tags: [],
16+
tags: []
1717
}
1818
)
1919
.promise();

src/transforms/v2-to-v3/__fixtures__/s3-upload/options.output.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ await new Upload({
99
Body: "BODY",
1010
Bucket: "Bucket",
1111
ContentType: "ContentType",
12-
Key: "Key",
12+
Key: "Key"
1313
},
1414

1515
partSize: 1024 * 1024 * 5,

src/transforms/v2-to-v3/__fixtures__/s3-upload/param-identifier.input.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const uploadParams = {
55
Body: "BODY",
66
Bucket: "Bucket",
77
ContentType: "ContentType",
8-
Key: "Key",
8+
Key: "Key"
99
};
1010

1111
await client.upload(uploadParams).promise();

src/transforms/v2-to-v3/__fixtures__/s3-upload/param-identifier.output.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const uploadParams = {
66
Body: "BODY",
77
Bucket: "Bucket",
88
ContentType: "ContentType",
9-
Key: "Key",
9+
Key: "Key"
1010
};
1111

1212
await new Upload({

src/transforms/v2-to-v3/__fixtures__/s3-upload/service-import-deep.input.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ await client.upload({
55
Body: "BODY",
66
Bucket: "Bucket",
77
ContentType: "ContentType",
8-
Key: "Key",
8+
Key: "Key"
99
}).promise();

src/transforms/v2-to-v3/__fixtures__/s3-upload/service-import-deep.output.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ await new Upload({
99
Body: "BODY",
1010
Bucket: "Bucket",
1111
ContentType: "ContentType",
12-
Key: "Key",
12+
Key: "Key"
1313
}
1414
}).done();

src/transforms/v2-to-v3/__fixtures__/s3-upload/service-import-equals.input.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ await client.upload({
55
Body: "BODY",
66
Bucket: "Bucket",
77
ContentType: "ContentType",
8-
Key: "Key",
8+
Key: "Key"
99
}).promise();

src/transforms/v2-to-v3/__fixtures__/s3-upload/service-import-equals.output.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ await new Upload({
1111
Body: "BODY",
1212
Bucket: "Bucket",
1313
ContentType: "ContentType",
14-
Key: "Key",
14+
Key: "Key"
1515
}
1616
}).done();

src/transforms/v2-to-v3/__fixtures__/s3-upload/service-import.input.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ await client.upload({
55
Body: "BODY",
66
Bucket: "Bucket",
77
ContentType: "ContentType",
8-
Key: "Key",
8+
Key: "Key"
99
}).promise();

src/transforms/v2-to-v3/__fixtures__/s3-upload/service-import.output.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ await new Upload({
99
Body: "BODY",
1010
Bucket: "Bucket",
1111
ContentType: "ContentType",
12-
Key: "Key",
12+
Key: "Key"
1313
}
1414
}).done();

src/transforms/v2-to-v3/__fixtures__/s3-upload/service-require-deep.input.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ await client.upload({
55
Body: "BODY",
66
Bucket: "Bucket",
77
ContentType: "ContentType",
8-
Key: "Key",
8+
Key: "Key"
99
}).promise();

src/transforms/v2-to-v3/__fixtures__/s3-upload/service-require-deep.output.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ await new Upload({
1414
Body: "BODY",
1515
Bucket: "Bucket",
1616
ContentType: "ContentType",
17-
Key: "Key",
17+
Key: "Key"
1818
}
1919
}).done();

src/transforms/v2-to-v3/__fixtures__/s3-upload/service-require.input.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ await client.upload({
55
Body: "BODY",
66
Bucket: "Bucket",
77
ContentType: "ContentType",
8-
Key: "Key",
8+
Key: "Key"
99
}).promise();

src/transforms/v2-to-v3/__fixtures__/s3-upload/service-require.output.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ await new Upload({
1414
Body: "BODY",
1515
Bucket: "Bucket",
1616
ContentType: "ContentType",
17-
Key: "Key",
17+
Key: "Key"
1818
}
1919
}).done();

src/transforms/v2-to-v3/transformer.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import {
3636
getMostUsedIndentationType,
3737
getMostUsedStringLiteralQuote,
3838
getValueIndentedWithTabs,
39+
isTrailingCommaUsed,
3940
isTypeScriptFile,
4041
} from "./utils";
4142

@@ -79,6 +80,7 @@ const transformer = async (file: FileInfo, api: API) => {
7980
// Compute recast options before doing transformations
8081
const quote = getMostUsedStringLiteralQuote(j, source);
8182
const useTabs = getMostUsedIndentationType(file.source) === IndentationType.TAB;
83+
const trailingComma = isTrailingCommaUsed(j, source);
8284

8385
const awsGlobalConfig = getAwsGlobalConfig(j, source, v2GlobalName);
8486
for (const [v2ClientName, v3ClientMetadata] of Object.entries(clientMetadataRecord)) {
@@ -113,7 +115,7 @@ const transformer = async (file: FileInfo, api: API) => {
113115
replaceAwsUtilFunctions(j, source, v2GlobalName);
114116
removeGlobalModule(j, source, v2GlobalName);
115117

116-
const sourceString = source.toSource({ quote, useTabs });
118+
const sourceString = source.toSource({ quote, useTabs, trailingComma });
117119

118120
if (useTabs) {
119121
// Refs: https://github.com/benjamn/recast/issues/315

src/transforms/v2-to-v3/utils/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ export * from "./getClientNewExpression";
33
export * from "./getMostUsedStringLiteralQuote";
44
export * from "./getMostUsedIndentationType";
55
export * from "./getValueIndentedWithTabs";
6+
export * from "./isTrailingCommaUsed";
67
export * from "./isTypeScriptFile";
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { Collection, JSCodeshift } from "jscodeshift";
2+
3+
export const isTrailingCommaUsed = (j: JSCodeshift, source: Collection<unknown>) => {
4+
for (const node of source.find(j.ObjectExpression).nodes()) {
5+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
6+
// @ts-ignore Property 'extra' does not exist on type 'ObjectExpression'.
7+
if (node.extra && node.extra.trailingComma) {
8+
return true;
9+
}
10+
}
11+
return false;
12+
};

0 commit comments

Comments
 (0)