Skip to content

chore: migrate eslint-plugin-import to eslint-plugin-import-x #11217

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
45 changes: 23 additions & 22 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import eslintCommentsPlugin from '@eslint-community/eslint-plugin-eslint-comment
import tseslintInternalPlugin from '@typescript-eslint/eslint-plugin-internal';
import vitestPlugin from '@vitest/eslint-plugin';
import eslintPluginPlugin from 'eslint-plugin-eslint-plugin';
import importPlugin from 'eslint-plugin-import';
import importXPlugin, { createNodeResolver } from 'eslint-plugin-import-x';
import jsdocPlugin from 'eslint-plugin-jsdoc';
import jsxA11yPlugin from 'eslint-plugin-jsx-a11y';
import perfectionistPlugin from 'eslint-plugin-perfectionist';
Expand Down Expand Up @@ -37,7 +37,7 @@ export default tseslint.config(
['@typescript-eslint']: tseslint.plugin,
['@typescript-eslint/internal']: tseslintInternalPlugin,
['eslint-plugin']: eslintPluginPlugin,
['import']: importPlugin,
['import-x']: importXPlugin,
['jsdoc']: jsdocPlugin,
// @ts-expect-error -- https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/pull/1038
['jsx-a11y']: jsxA11yPlugin.flatConfigs.recommended.plugins['jsx-a11y'],
Expand All @@ -53,6 +53,7 @@ export default tseslint.config(
},
/* eslint-enable no-useless-computed-key */
settings: {
'import-x/resolver-next': createNodeResolver(),
perfectionist: {
order: 'asc',
partitionByComment: true,
Expand Down Expand Up @@ -260,24 +261,24 @@ export default tseslint.config(
],

//
// eslint-plugin-import
// eslint-plugin-import-x
//
// enforces consistent type specifier style for named imports
'import/consistent-type-specifier-style': 'error',
'import-x/consistent-type-specifier-style': 'error',
// disallow non-import statements appearing before import statements
'import/first': 'error',
'import-x/first': 'error',
// Require a newline after the last import/require in a group
'import/newline-after-import': 'error',
'import-x/newline-after-import': 'error',
// Forbid import of modules using absolute paths
'import/no-absolute-path': 'error',
'import-x/no-absolute-path': 'error',
// disallow AMD require/define
'import/no-amd': 'error',
'import-x/no-amd': 'error',
// forbid default exports - we want to standardize on named exports so that imported names are consistent
'import/no-default-export': 'error',
'import-x/no-default-export': 'error',
// disallow imports from duplicate paths
'import/no-duplicates': 'error',
'import-x/no-duplicates': 'error',
// Forbid the use of extraneous packages
'import/no-extraneous-dependencies': [
'import-x/no-extraneous-dependencies': [
'error',
{
devDependencies: true,
Expand All @@ -286,15 +287,15 @@ export default tseslint.config(
},
],
// Forbid mutable exports
'import/no-mutable-exports': 'error',
'import-x/no-mutable-exports': 'error',
// Prevent importing the default as if it were named
'import/no-named-default': 'error',
'import-x/no-named-default': 'error',
// Prohibit named exports
'import/no-named-export': 'off', // we want everything to be a named export
'import-x/no-named-export': 'off', // we want everything to be a named export
// Forbid a module from importing itself
'import/no-self-import': 'error',
'import-x/no-self-import': 'error',
// Require modules with a single export to use a default export
'import/prefer-default-export': 'off', // we want everything to be named
'import-x/prefer-default-export': 'off', // we want everything to be named

// enforce a sort order across the codebase
'perfectionist/sort-imports': 'error',
Expand Down Expand Up @@ -440,7 +441,7 @@ export default tseslint.config(
],
rules: {
// requirement
'import/no-default-export': 'off',
'import-x/no-default-export': 'off',
},
},

Expand Down Expand Up @@ -484,7 +485,7 @@ export default tseslint.config(
],

// specifically for rules - default exports makes the tooling easier
'import/no-default-export': 'off',
'import-x/no-default-export': 'off',

'no-restricted-syntax': [
'error',
Expand All @@ -502,7 +503,7 @@ export default tseslint.config(
files: ['packages/eslint-plugin/src/rules/index.ts'],
rules: {
// enforce alphabetical ordering
'import/order': ['error', { alphabetize: { order: 'asc' } }],
'import-x/order': ['error', { alphabetize: { order: 'asc' } }],
'sort-keys': 'error',
},
},
Expand Down Expand Up @@ -567,7 +568,7 @@ export default tseslint.config(
files: ['packages/website/**/*.{ts,tsx,mts,cts,js,jsx}'],
rules: {
'@typescript-eslint/internal/prefer-ast-types-enum': 'off',
'import/no-default-export': 'off',
'import-x/no-default-export': 'off',
'react/jsx-no-target-blank': 'off',
'react/no-unescaped-entities': 'off',
'react/prop-types': 'off',
Expand All @@ -582,7 +583,7 @@ export default tseslint.config(
{
files: ['packages/website/src/**/*.{ts,tsx,cts,mts}'],
rules: {
'import/no-default-export': 'off',
'import-x/no-default-export': 'off',
// allow console logs in the website to help with debugging things in production
'no-console': 'off',
},
Expand All @@ -594,7 +595,7 @@ export default tseslint.config(
],
rules: {
// mocks and declaration files have to mirror their original package
'import/no-default-export': 'off',
'import-x/no-default-export': 'off',
},
},
{
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
"cspell": "^9.0.0",
"eslint": "^9.26.0",
"eslint-plugin-eslint-plugin": "^6.3.1",
"eslint-plugin-import": "^2.31.0",
"eslint-plugin-import-x": "^4.11.1",
"eslint-plugin-jsdoc": "^50.5.0",
"eslint-plugin-jsx-a11y": "^6.10.2",
"eslint-plugin-perfectionist": "^3.9.1",
Expand Down Expand Up @@ -116,6 +116,7 @@
"@types/node": "^22.0.0",
"@types/react": "^18.2.14",
"eslint-plugin-eslint-plugin@^5.5.0": "patch:eslint-plugin-eslint-plugin@npm%3A5.5.1#./.yarn/patches/eslint-plugin-eslint-plugin-npm-5.5.1-4206c2506d.patch",
"react-helmet-async": "npm:@slorber/react-helmet-async@1.3.0",
"prettier": "3.5.0",
"pretty-format": "^29",
"react-split-pane@^0.1.92": "patch:react-split-pane@npm%3A0.1.92#./.yarn/patches/react-split-pane-npm-0.1.92-93dbf51dff.patch",
Expand Down
15 changes: 8 additions & 7 deletions packages/website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@
},
"dependencies": {
"@babel/runtime": "^7.24.4",
"@docusaurus/core": "^3.2.1",
"@docusaurus/plugin-client-redirects": "^3.2.1",
"@docusaurus/plugin-pwa": "^3.2.1",
"@docusaurus/preset-classic": "^3.2.1",
"@docusaurus/remark-plugin-npm2yarn": "^3.2.1",
"@docusaurus/theme-common": "^3.2.1",
"@docusaurus/core": "^3.7.0",
"@docusaurus/plugin-client-redirects": "^3.7.0",
"@docusaurus/plugin-content-blog": "^3.7.0",
"@docusaurus/plugin-pwa": "^3.7.0",
"@docusaurus/preset-classic": "^3.7.0",
"@docusaurus/remark-plugin-npm2yarn": "^3.7.0",
"@docusaurus/theme-common": "^3.7.0",
"@typescript-eslint/parser": "workspace:*",
"@typescript-eslint/website-eslint": "workspace:*",
"@uiw/react-shields": "2.0.1",
Expand All @@ -56,7 +57,7 @@
"react": "^18.2.0"
},
"devDependencies": {
"@docusaurus/module-type-aliases": "^3.2.1",
"@docusaurus/module-type-aliases": "^3.7.0",
"@types/mdast": "^4.0.3",
"@types/react": "*",
"@types/unist": "^3.0.2",
Expand Down
Loading