Skip to content

Commit

Permalink
Filter client names received from new expressions and TS Types (#329)
Browse files Browse the repository at this point in the history
  • Loading branch information
trivikr committed Jan 7, 2023
1 parent cb8d6f2 commit a998205
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/shaggy-jobs-hide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"aws-sdk-js-codemod": patch
---

Filter client names received from new expressions and TS Types
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// ToDo: Update when transformation is added.
// Current test verifies error is not thrown.
import AWS from "aws-sdk";

const credentials = new AWS.SharedIniFileCredentials({ profile: "my-profile" });
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// ToDo: Update when transformation is added.
// Current test verifies error is not thrown.
import AWS from "aws-sdk";

const credentials = new AWS.SharedIniFileCredentials({ profile: "my-profile" });
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Collection, Identifier, JSCodeshift, MemberExpression } from "jscodeshi

import { getV2ClientNewExpression } from "../utils";

export const getV2ClientNamesFromNewExpr = (
export const getNamesFromNewExpr = (
j: JSCodeshift,
source: Collection<unknown>,
v2GlobalName: string
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Collection, Identifier, JSCodeshift } from "jscodeshift";

export const getV2ClientNamesFromTSQualifiedName = (
export const getNamesFromTSQualifiedName = (
j: JSCodeshift,
source: Collection<unknown>,
v2GlobalName: string
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import { Collection, JSCodeshift } from "jscodeshift";

import { getV2ClientNamesFromNewExpr } from "./getV2ClientNamesFromNewExpr";
import { getV2ClientNamesFromTSQualifiedName } from "./getV2ClientNamesFromTSQualifiedName";
import { CLIENT_NAMES } from "../config";
import { getNamesFromNewExpr } from "./getNamesFromNewExpr";
import { getNamesFromTSQualifiedName } from "./getNamesFromTSQualifiedName";

export const getV2ClientNamesFromGlobal = (
j: JSCodeshift,
source: Collection<unknown>,
v2GlobalName: string
): string[] => {
const namesFromNewExpr = getV2ClientNamesFromNewExpr(j, source, v2GlobalName);
const namesFromTSQualifiedName = getV2ClientNamesFromTSQualifiedName(j, source, v2GlobalName);
return [...new Set([...namesFromNewExpr, ...namesFromTSQualifiedName])];
const namesFromNewExpr = getNamesFromNewExpr(j, source, v2GlobalName);
const namesFromTSQualifiedName = getNamesFromTSQualifiedName(j, source, v2GlobalName);

return [...new Set([...namesFromNewExpr, ...namesFromTSQualifiedName])].filter((name) =>
CLIENT_NAMES.includes(name)
);
};

0 comments on commit a998205

Please sign in to comment.