diff --git a/.changeset/four-badgers-care.md b/.changeset/four-badgers-care.md new file mode 100644 index 000000000..3827f5495 --- /dev/null +++ b/.changeset/four-badgers-care.md @@ -0,0 +1,5 @@ +--- +"aws-sdk-js-codemod": patch +--- + +Use 'not supported' constant for early return diff --git a/src/transforms/v2-to-v3/apis/addNotSupportedClientComments.ts b/src/transforms/v2-to-v3/apis/addNotSupportedClientComments.ts index 478b29205..fd97752fa 100644 --- a/src/transforms/v2-to-v3/apis/addNotSupportedClientComments.ts +++ b/src/transforms/v2-to-v3/apis/addNotSupportedClientComments.ts @@ -1,6 +1,6 @@ import { Collection, JSCodeshift } from "jscodeshift"; -import { FUNCTION_TYPE_LIST, S3 } from "../config"; +import { FUNCTION_TYPE_LIST, NOT_SUPPORTED_COMMENT, S3 } from "../config"; import { ClientIdentifier } from "../types"; import { getClientApiCallExpression } from "./getClientApiCallExpression"; import { getClientWaiterCallExpression } from "./getClientWaiterCallExpression"; @@ -29,11 +29,7 @@ export const addNotSupportedClientComments = ( if (FUNCTION_TYPE_LIST.includes(args[args.length - 1].type)) { const comments = callExpression.node.comments || []; - comments.push( - j.commentLine( - " Waiters with callbacks are not supported in AWS SDK for JavaScript (v3)." - ) - ); + comments.push(j.commentLine(` Waiters with callbacks are ${NOT_SUPPORTED_COMMENT}.`)); comments.push( j.commentLine( " Please convert to `await client.waitFor(state, params).promise()`, and re-run aws-sdk-js-codemod." @@ -68,9 +64,7 @@ export const addNotSupportedClientComments = ( if (FUNCTION_TYPE_LIST.includes(args[args.length - 1].type)) { const comments = callExpression.node.comments || []; comments.push( - j.commentLine( - ` ${apiDescription} with callbacks are not supported in AWS SDK for JavaScript (v3).` - ) + j.commentLine(` ${apiDescription} with callbacks are ${NOT_SUPPORTED_COMMENT}.`) ); comments.push( j.commentLine( diff --git a/src/transforms/v2-to-v3/config/constants.ts b/src/transforms/v2-to-v3/config/constants.ts index e7d307705..6bdf3d0ad 100644 --- a/src/transforms/v2-to-v3/config/constants.ts +++ b/src/transforms/v2-to-v3/config/constants.ts @@ -13,3 +13,5 @@ export const FUNCTION_TYPE_LIST = [ "ArrowFunctionExpression", ]; export const STRING_LITERAL_TYPE_LIST = ["Literal", "StringLiteral"]; + +export const NOT_SUPPORTED_COMMENT = "not supported in AWS SDK for JavaScript (v3)"; diff --git a/src/transforms/v2-to-v3/transformer.ts b/src/transforms/v2-to-v3/transformer.ts index 055536847..ca454ac1b 100644 --- a/src/transforms/v2-to-v3/transformer.ts +++ b/src/transforms/v2-to-v3/transformer.ts @@ -25,7 +25,7 @@ import { getClientNamesFromGlobal, getClientNamesRecord, } from "./client-names"; -import { S3 } from "./config"; +import { NOT_SUPPORTED_COMMENT, S3 } from "./config"; import { addClientModules, getGlobalNameFromModule, getImportType, removeModules } from "./modules"; import { removeTypesFromTSQualifiedName, replaceTSTypeReference } from "./ts-type"; import { @@ -70,7 +70,7 @@ const transformer = async (file: FileInfo, api: API) => { addNotSupportedClientComments(j, source, { v2ClientName, clientIdentifiers }); } - if (source.toSource() !== file.source) { + if (source.toSource().includes(NOT_SUPPORTED_COMMENT)) { return source.toSource(); }