Skip to content

Commit

Permalink
Stop violating no-import-type-side-effects
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Silbermann committed Feb 14, 2024
1 parent b5bdbae commit 48c64e5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
14 changes: 7 additions & 7 deletions transforms/__tests__/scoped-jsx.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe("transform scoped-jsx", () => {
declare const element: JSX.Element;
`),
).toMatchInlineSnapshot(`
"import { type JSX } from "react";
"import type { JSX } from "react";
declare const element: JSX.Element;"
`);
});
Expand All @@ -58,7 +58,7 @@ describe("transform scoped-jsx", () => {
`),
).toMatchInlineSnapshot(`
"import type React from 'react';
import { type JSX } from "react";
import type { JSX } from "react";
declare const element: JSX.Element;"
`);
});
Expand All @@ -71,7 +71,7 @@ describe("transform scoped-jsx", () => {
`),
).toMatchInlineSnapshot(`
"import * as React from 'react';
import { type JSX } from "react";
import type { JSX } from "react";
declare const element: JSX.Element;"
`);
});
Expand All @@ -84,7 +84,7 @@ describe("transform scoped-jsx", () => {
`),
).toMatchInlineSnapshot(`
"import type * as React from 'react';
import { type JSX } from "react";
import type { JSX } from "react";
declare const element: JSX.Element;"
`);
});
Expand Down Expand Up @@ -136,7 +136,7 @@ describe("transform scoped-jsx", () => {
declare const element: JSX.Element;
`),
).toMatchInlineSnapshot(`
"import { type JSX } from "react";
"import type { JSX } from "react";
const React = require('react');
declare const element: JSX.Element;"
`);
Expand All @@ -154,7 +154,7 @@ describe("transform scoped-jsx", () => {
"import {} from 'react-dom'
import {} from '@testing-library/react'
import { type JSX } from "react";
import type { JSX } from "react";
declare const element: JSX.Element;"
`);
Expand All @@ -170,7 +170,7 @@ describe("transform scoped-jsx", () => {
).toMatchInlineSnapshot(`
"import * as React from 'react'
import { type JSX } from "react";
import type { JSX } from "react";
declare const attributes: JSX.LibraryManagedAttributes<A, B>;"
`);
Expand Down
4 changes: 2 additions & 2 deletions transforms/scoped-jsx.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ const deprecatedReactChildTransform = (file, api) => {
addReactTypeImport(j, reactImport);
} else {
const importSpecifier = j.importSpecifier(j.identifier("JSX"));
// @ts-expect-error -- Missing types in jscodeshift. Babel uses `importKind`: https://astexplorer.net/#/gist/a76bd35f28483a467fef29d3c63aac9b/0e7ba6688fc09bd11b92197349b2384bb4c94574
importSpecifier.importKind = "type";
const jsxNamespaceImport = j.importDeclaration(
[importSpecifier],
j.stringLiteral("react"),
// Not using inline type import because it violates https://typescript-eslint.io/rules/no-import-type-side-effects/
"type",
);

const lastImport = ast.find(j.ImportDeclaration).at(-1);
Expand Down

0 comments on commit 48c64e5

Please sign in to comment.