Skip to content

Commit

Permalink
Remove trailing comma from ObjectProperty require (#719)
Browse files Browse the repository at this point in the history
  • Loading branch information
trivikr authored Nov 12, 2023
1 parent 0ac2c98 commit 304ae20
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/pretty-tips-cry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"aws-sdk-js-codemod": patch
---

Remove trailing comma from ObjectProperty require
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const AWS = require("aws-sdk");

const client = new AWS.DynamoDB({
region: "us-west-2",
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const { DynamoDB } = require("@aws-sdk/client-dynamodb");

const client = new DynamoDB({
region: "us-west-2",
});
6 changes: 5 additions & 1 deletion src/transforms/v2-to-v3/utils/getFormattedSourceString.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ export const getFormattedSourceString = (source: string) =>
.replace(
/\{\n {2}([\w,\n ]+)\n\} = require\((['"])@aws-sdk/g,
(_, identifiers, quote) =>
`{ ${identifiers.split(",\n ").join(", ")} } = require(${quote}@aws-sdk`
`{ ${identifiers
.split(",")
.map((str: string) => str.trimLeft())
.filter((str: string) => str !== "")
.join(", ")} } = require(${quote}@aws-sdk`
)
// Remove extra newlines between require declarations.
.replace(
Expand Down

0 comments on commit 304ae20

Please sign in to comment.