Skip to content

Commit

Permalink
fix: use import-x instead of import
Browse files Browse the repository at this point in the history
  • Loading branch information
CyanSalt committed May 27, 2024
1 parent 1d6d126 commit 98d4cea
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 26 deletions.
25 changes: 12 additions & 13 deletions configs/import.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import { createRequire } from 'node:module'
import { fixupPluginRules } from '@eslint/compat'
import importPlugin from 'eslint-plugin-import'
import importX from 'eslint-plugin-import-x'
import { defineConfig } from '../config.js'

export default defineConfig(options => {
const { resolve } = createRequire(import.meta.url)
return [
{
plugins: {
import: fixupPluginRules(importPlugin),
'import-x': importX,
},
settings: {
'import/internal-regex': '^@/',
'import/resolver': {
'import-x/internal-regex': '^@/',
'import-x/resolver': {
// Must go before any other resolvers for typescript files
[resolve('eslint-import-resolver-typescript')]: {
extensions: [
Expand Down Expand Up @@ -41,27 +40,27 @@ export default defineConfig(options => {
],
},
},
'import/parsers': {
'import-x/parsers': {
[resolve('@typescript-eslint/parser')]: ['.cts', '.mts', '.ts', '.tsx'],
[resolve('vue-eslint-parser')]: ['.vue'],
},
},
rules: {
// 自动将类型导入修改为 import type 语句
'import/consistent-type-specifier-style': ['warn', 'prefer-top-level'],
'import-x/consistent-type-specifier-style': ['warn', 'prefer-top-level'],
// import 语句必须在最前
'import/first': 'error',
'import-x/first': 'error',
// 自动为 import 之后添加空行
'import/newline-after-import': 'warn',
'import-x/newline-after-import': 'warn',
// 自动修复重复的 import
'no-duplicate-imports': 'off',
'import/no-duplicates': 'warn',
'import-x/no-duplicates': 'warn',
// 自动去除空的导入块
'import/no-empty-named-blocks': 'warn',
'import-x/no-empty-named-blocks': 'warn',
// 禁止导出 let 和 var 声明的可变变量
'import/no-mutable-exports': 'error',
'import-x/no-mutable-exports': 'error',
// 必须按照 内置 > 外部模块 > aliases > '../' > './' 声明 import 顺序
'import/order': ['warn', {
'import-x/order': ['warn', {
groups: ['builtin', 'external', 'internal', 'parent', 'sibling'],
pathGroupsExcludedImportTypes: ['builtin'],
alphabetize: { order: 'asc', orderImportKind: 'asc' },
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
"eslint-flat-config-utils": "^0.2.4",
"eslint-import-resolver-alias": "^1.1.2",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-galaxy": "^1.34.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-galaxy": "^1.34.1",
"eslint-plugin-import-x": "^0.5.1",
"eslint-plugin-react": "^7.34.1",
"eslint-plugin-react-hooks": "^4.6.2",
"eslint-plugin-unicorn": "^53.0.0",
Expand Down
49 changes: 40 additions & 9 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/javascript.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from 'node:path'
// eslint-disable-next-line import/order
// eslint-disable-next-line import-x/order
import fs from 'node:fs'

// eslint-disable-next-line no-eval
Expand Down
2 changes: 1 addition & 1 deletion tests/typescript.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from 'node:path'
// eslint-disable-next-line import/order
// eslint-disable-next-line import-x/order
import fs from 'node:fs'

// eslint-disable-next-line no-eval
Expand Down

0 comments on commit 98d4cea

Please sign in to comment.