Skip to content

fix: Don't use import statement #69

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/strange-news-smoke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"types-react-codemod": patch
---

Don't use `import` statement.

Fixes errors like "SyntaxError: Cannot use import statement outside a module".
16 changes: 1 addition & 15 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,7 @@ module.exports = {
extends: "eslint:recommended",
parserOptions: {
ecmaVersion: "latest",
sourceType: "commonjs",
sourceType: "script",
},
rules: {},
overrides: [
{
files: "**/__tests__/**/*",
parserOptions: {
sourceType: "module",
},
},
{
files: "transforms/**/*",
parserOptions: {
sourceType: "module",
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Responsible for hiding the wrong module usage.

},
},
],
};
3 changes: 0 additions & 3 deletions babel.config.js

This file was deleted.

8 changes: 4 additions & 4 deletions bin/__tests__/types-react-codemod.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, expect, test } from "@jest/globals";
import * as childProcess from "child_process";
import * as path from "path";
import { promisify } from "util";
const { describe, expect, test } = require("@jest/globals");
const childProcess = require("child_process");
const path = require("path");
const { promisify } = require("util");

describe("types-react-codemod", () => {
const exec = promisify(childProcess.exec);
Expand Down
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const config = {

// A set of global variables that need to be available in all test environments
// globals: {},
injectGlobals: false,
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Required due to jestjs/jest#9920


// The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
// maxWorkers: "50%",
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"@types/jscodeshift": "^0.11.3",
"@types/node": "^16.10.0",
"@types/yargs": "^17.0.10",
"babel-jest": "^28.0.0",
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No longer needed since we now use commonJS in tests

"dedent": "^0.7.0",
"eslint": "^8.12.0",
"jest": "^28.0.0",
Expand Down
8 changes: 4 additions & 4 deletions transforms/__tests__/context-any.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, expect, test } from "@jest/globals";
import dedent from "dedent";
import * as JscodeshiftTestUtils from "jscodeshift/dist/testUtils";
import contextAnyTransform from "../context-any";
const { describe, expect, test } = require("@jest/globals");
const dedent = require("dedent");
const JscodeshiftTestUtils = require("jscodeshift/dist/testUtils");
const contextAnyTransform = require("../context-any");

function applyTransform(source, options = {}) {
return JscodeshiftTestUtils.applyTransform(contextAnyTransform, options, {
Expand Down
8 changes: 4 additions & 4 deletions transforms/__tests__/deprecated-react-child.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, expect, test } from "@jest/globals";
import dedent from "dedent";
import * as JscodeshiftTestUtils from "jscodeshift/dist/testUtils";
import deprecatedReactChildTransform from "../deprecated-react-child";
const { describe, expect, test } = require("@jest/globals");
const dedent = require("dedent");
const JscodeshiftTestUtils = require("jscodeshift/dist/testUtils");
const deprecatedReactChildTransform = require("../deprecated-react-child");

function applyTransform(source, options = {}) {
return JscodeshiftTestUtils.applyTransform(
Expand Down
8 changes: 4 additions & 4 deletions transforms/__tests__/deprecated-react-text.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, expect, test } from "@jest/globals";
import dedent from "dedent";
import * as JscodeshiftTestUtils from "jscodeshift/dist/testUtils";
import deprecatedReactTextTransform from "../deprecated-react-text";
const { describe, expect, test } = require("@jest/globals");
const dedent = require("dedent");
const JscodeshiftTestUtils = require("jscodeshift/dist/testUtils");
const deprecatedReactTextTransform = require("../deprecated-react-text");

function applyTransform(source, options = {}) {
return JscodeshiftTestUtils.applyTransform(
Expand Down
8 changes: 4 additions & 4 deletions transforms/__tests__/deprecated-react-type.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, expect, test } from "@jest/globals";
import dedent from "dedent";
import * as JscodeshiftTestUtils from "jscodeshift/dist/testUtils";
import deprecatedReactTypeTransform from "../deprecated-react-type";
const { describe, expect, test } = require("@jest/globals");
const dedent = require("dedent");
const JscodeshiftTestUtils = require("jscodeshift/dist/testUtils");
const deprecatedReactTypeTransform = require("../deprecated-react-type");

function applyTransform(source, options = {}) {
return JscodeshiftTestUtils.applyTransform(
Expand Down
8 changes: 4 additions & 4 deletions transforms/__tests__/deprecated-sfc-element.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, expect, test } from "@jest/globals";
import dedent from "dedent";
import * as JscodeshiftTestUtils from "jscodeshift/dist/testUtils";
import deprecatedSFCElementTransform from "../deprecated-sfc-element";
const { describe, expect, test } = require("@jest/globals");
const dedent = require("dedent");
const JscodeshiftTestUtils = require("jscodeshift/dist/testUtils");
const deprecatedSFCElementTransform = require("../deprecated-sfc-element");

function applyTransform(source, options = {}) {
return JscodeshiftTestUtils.applyTransform(
Expand Down
8 changes: 4 additions & 4 deletions transforms/__tests__/deprecated-sfc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, expect, test } from "@jest/globals";
import dedent from "dedent";
import * as JscodeshiftTestUtils from "jscodeshift/dist/testUtils";
import deprecatedSFCTransform from "../deprecated-sfc";
const { describe, expect, test } = require("@jest/globals");
const dedent = require("dedent");
const JscodeshiftTestUtils = require("jscodeshift/dist/testUtils");
const deprecatedSFCTransform = require("../deprecated-sfc");

function applyTransform(source, options = {}) {
return JscodeshiftTestUtils.applyTransform(deprecatedSFCTransform, options, {
Expand Down
8 changes: 4 additions & 4 deletions transforms/__tests__/deprecated-stateless-component.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, expect, test } from "@jest/globals";
import dedent from "dedent";
import * as JscodeshiftTestUtils from "jscodeshift/dist/testUtils";
import deprecatedStatelessComponent from "../deprecated-stateless-component";
const { describe, expect, test } = require("@jest/globals");
const dedent = require("dedent");
const JscodeshiftTestUtils = require("jscodeshift/dist/testUtils");
const deprecatedStatelessComponent = require("../deprecated-stateless-component");

function applyTransform(source, options = {}) {
return JscodeshiftTestUtils.applyTransform(
Expand Down
8 changes: 4 additions & 4 deletions transforms/__tests__/deprecated-void-function-component.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, expect, test } from "@jest/globals";
import dedent from "dedent";
import * as JscodeshiftTestUtils from "jscodeshift/dist/testUtils";
import deprecatedVoidFunctionComponentTransform from "../deprecated-void-function-component";
const { describe, expect, test } = require("@jest/globals");
const dedent = require("dedent");
const JscodeshiftTestUtils = require("jscodeshift/dist/testUtils");
const deprecatedVoidFunctionComponentTransform = require("../deprecated-void-function-component");

function applyTransform(source, options = {}) {
return JscodeshiftTestUtils.applyTransform(
Expand Down
8 changes: 4 additions & 4 deletions transforms/__tests__/implicit-children.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, expect, test } from "@jest/globals";
import dedent from "dedent";
import * as JscodeshiftTestUtils from "jscodeshift/dist/testUtils";
import implicitChildrenTransform from "../implicit-children";
const { describe, expect, test } = require("@jest/globals");
const dedent = require("dedent");
const JscodeshiftTestUtils = require("jscodeshift/dist/testUtils");
const implicitChildrenTransform = require("../implicit-children");

function applyTransform(source, options = {}) {
return JscodeshiftTestUtils.applyTransform(
Expand Down
11 changes: 4 additions & 7 deletions transforms/__tests__/preset-18.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { beforeEach, describe, expect, jest, test } from "@jest/globals";
import dedent from "dedent";
import * as JscodeshiftTestUtils from "jscodeshift/dist/testUtils";
const { beforeEach, describe, expect, jest, test } = require("@jest/globals");
const dedent = require("dedent");
const JscodeshiftTestUtils = require("jscodeshift/dist/testUtils");

describe("preset-18", () => {
let preset18Transform;
Expand All @@ -26,10 +26,7 @@ describe("preset-18", () => {
const transform = jest.fn();

jest.doMock(moduleName, () => {
return {
__esModule: true,
default: transform,
};
return transform;
});

return transform;
Expand Down
11 changes: 4 additions & 7 deletions transforms/__tests__/preset-19.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { beforeEach, describe, expect, jest, test } from "@jest/globals";
import dedent from "dedent";
import * as JscodeshiftTestUtils from "jscodeshift/dist/testUtils";
const { beforeEach, describe, expect, jest, test } = require("@jest/globals");
const dedent = require("dedent");
const JscodeshiftTestUtils = require("jscodeshift/dist/testUtils");

describe("preset-19", () => {
let preset19Transform;
Expand All @@ -22,10 +22,7 @@ describe("preset-19", () => {
const transform = jest.fn();

jest.doMock(moduleName, () => {
return {
__esModule: true,
default: transform,
};
return transform;
});

return transform;
Expand Down
8 changes: 4 additions & 4 deletions transforms/__tests__/useCallback-implicit-any.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, expect, test } from "@jest/globals";
import dedent from "dedent";
import * as JscodeshiftTestUtils from "jscodeshift/dist/testUtils";
import useCallbackAnyTransform from "../useCallback-implicit-any";
const { describe, expect, test } = require("@jest/globals");
const dedent = require("dedent");
const JscodeshiftTestUtils = require("jscodeshift/dist/testUtils");
const useCallbackAnyTransform = require("../useCallback-implicit-any");

function applyTransform(source, options = {}) {
return JscodeshiftTestUtils.applyTransform(useCallbackAnyTransform, options, {
Expand Down
14 changes: 7 additions & 7 deletions transforms/preset-18.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import contextAnyTransform from "./context-any";
import deprecatedReactTypeTransform from "./deprecated-react-type";
import deprecatedSFCTransform from "./deprecated-sfc";
import deprecatedSFCElementTransform from "./deprecated-sfc-element";
import deprecatedStatelessComponentTransform from "./deprecated-stateless-component";
import implicitChildrenTransform from "./implicit-children";
import implicitAnyTransform from "./useCallback-implicit-any";
const contextAnyTransform = require("./context-any");
const deprecatedReactTypeTransform = require("./deprecated-react-type");
const deprecatedSFCTransform = require("./deprecated-sfc");
const deprecatedSFCElementTransform = require("./deprecated-sfc-element");
const deprecatedStatelessComponentTransform = require("./deprecated-stateless-component");
const implicitChildrenTransform = require("./implicit-children");
const implicitAnyTransform = require("./useCallback-implicit-any");

/**
* @type {import('jscodeshift').Transform}
Expand Down
6 changes: 3 additions & 3 deletions transforms/preset-19.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import deprecatedReactChildTransform from "./deprecated-react-child";
import deprecatedReactTextTransform from "./deprecated-react-text";
import deprecatedVoidFunctionComponentTransform from "./deprecated-void-function-component";
const deprecatedReactChildTransform = require("./deprecated-react-child");
const deprecatedReactTextTransform = require("./deprecated-react-text");
const deprecatedVoidFunctionComponentTransform = require("./deprecated-void-function-component");

/**
* @type {import('jscodeshift').Transform}
Expand Down
4 changes: 2 additions & 2 deletions transforms/utils/__tests__/parseSync.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, test } from "@jest/globals";
import parseSync from "../parseSync";
const { describe, expect, test } = require("@jest/globals");
const parseSync = require("../parseSync");

describe("parseSync", () => {
test("oldschool type casts in ts files", () => {
Expand Down
3 changes: 1 addition & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2460,7 +2460,7 @@ __metadata:
languageName: node
linkType: hard

"babel-jest@npm:^28.0.0, babel-jest@npm:^28.1.0":
"babel-jest@npm:^28.1.0":
version: 28.1.0
resolution: "babel-jest@npm:28.1.0"
dependencies:
Expand Down Expand Up @@ -7289,7 +7289,6 @@ __metadata:
"@types/jscodeshift": ^0.11.3
"@types/node": ^16.10.0
"@types/yargs": ^17.0.10
babel-jest: ^28.0.0
dedent: ^0.7.0
eslint: ^8.12.0
inquirer: ^8.2.2
Expand Down