-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prefer import over require when both are present (#652)
- Loading branch information
Showing
9 changed files
with
47 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"aws-sdk-js-codemod": patch | ||
--- | ||
|
||
Prefer import over require when both are present |
4 changes: 4 additions & 0 deletions
4
src/transforms/v2-to-v3/__fixtures__/misc/import-over-require.input.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { DynamoDB } from "aws-sdk"; | ||
const AWS = require("aws-sdk"); | ||
|
||
const client: DynamoDB = new AWS.DynamoDB(); |
3 changes: 3 additions & 0 deletions
3
src/transforms/v2-to-v3/__fixtures__/misc/import-over-require.output.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { DynamoDB } from "@aws-sdk/client-dynamodb"; | ||
|
||
const client: DynamoDB = new DynamoDB(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
import { Collection, JSCodeshift } from "jscodeshift"; | ||
import { hasImport } from "./hasImport"; | ||
import { hasImportEquals } from "./hasImportEquals"; | ||
import { hasRequire } from "./hasRequire"; | ||
import { ImportType } from "./types"; | ||
|
||
export const getImportType = (j: JSCodeshift, source: Collection<unknown>) => | ||
hasRequire(j, source) | ||
? ImportType.REQUIRE | ||
hasImport(j, source) | ||
? ImportType.IMPORT | ||
: hasImportEquals(j, source) | ||
? ImportType.IMPORT_EQUALS | ||
: ImportType.IMPORT; | ||
: ImportType.REQUIRE; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Collection, JSCodeshift } from "jscodeshift"; | ||
import { PACKAGE_NAME } from "../config"; | ||
|
||
export const hasImport = (j: JSCodeshift, source: Collection<unknown>) => | ||
source | ||
.find(j.ImportDeclaration) | ||
.filter((importDeclaration) => { | ||
const { value: sourceValue } = importDeclaration.value.source; | ||
return typeof sourceValue === "string" && sourceValue.startsWith(PACKAGE_NAME); | ||
}) | ||
.size() > 0; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters