.eslintrc 到 eslint.config.mjs -> 迁移到新配置语法时出现错误

问题描述 投票:0回答:1

这是我的旧 .eslintrc

{
  "env": {
    "browser": true,
    "es6": true,
    "node": true
  },
  "extends": [
    "eslint:recommended",
    "plugin:react/recommended",
    "plugin:@typescript-eslint/eslint-recommended",
    "plugin:@typescript-eslint/recommended",
    "plugin:import/errors",
    "plugin:import/warnings"
  ],
  "parser": "@typescript-eslint/parser",
  "settings": {
    "import/resolver": {
      "node": {
        "extensions": [".js", ".jsx", ".ts", ".tsx"]
      },
      "alias": {
        "map": [
          ["@renderer", "./src/renderer"],
          ["@components", "./src/renderer/components"],
          ["@common", "./src/common"],
          ["@main", "./src/main"],
          ["@src", "./src"],
          ["@misc", "./misc"],
          ["@assets", "./assets"]
        ],
        "extensions": [".js", ".jsx", ".ts", ".tsx"]
      }
    },
    "react": {
      "version": "detect"
    }
  },
  "rules": {
    "react/prop-types": "off",
    "@typescript-eslint/no-var-requires": "off"
  }
}

这是我的新 eslint.config.mjs

// eslint.config.js
import globals from 'globals'
import eslintPluginReact from 'eslint-plugin-react'
import typescriptEslint from '@typescript-eslint/eslint-plugin'

const filesList = ['src/**/*.js', 'src/**/*.jsx', 'src/**/*.ts', 'src/**/*.tsx']

export default [
  'eslint:recommended',
  /*
  {
    files: filesList,
    plugins: {
      react: eslintPluginReact
    },
    rules: {
      ...eslintPluginReact.configs.recommended.rules
    }
  },
  */
  typescriptEslint.recommended,
  {
    files: filesList,
    languageOptions: {
      ecmaVersion: 2022,
      sourceType: 'module',
      globals: {
        ...globals.browser,
        ...globals.node
      }
    },
    extends: [
      'eslint:recommended',
      'plugin:react/recommended',
      'plugin:@typescript-eslint/eslint-recommended',
      'plugin:@typescript-eslint/recommended',
      'plugin:import/errors',
      'plugin:import/warnings'
    ],
    parser: '@typescript-eslint/parser',
    settings: {
      'import/resolver': {
        node: {
          extensions: ['.js', '.jsx', '.ts', '.tsx']
        },
        alias: {
          map: [
            ['@renderer', './src/renderer'],
            ['@components', './src/renderer/components'],
            ['@common', './src/common'],
            ['@main', './src/main'],
            ['@src', './src'],
            ['@misc', './misc'],
            ['@assets', './assets']
          ],
          extensions: ['.js', '.jsx', '.ts', '.tsx']
        }
      },
      react: {
        version: 'detect'
      }
    },
    rules: {
      'react/prop-types': 'off',
      '@typescript-eslint/no-var-requires': 'off'
    }
  }
]

eslint 不喜欢它:

“类型错误:配置(未命名):用户定义索引 0 处出现意外的非对象配置。”

任何曾经位于“扩展”内部的外部配置。

我想我错过了一些东西,但没有文档也没有示例如何做到这一点。

javascript reactjs eslint
1个回答
0
投票

配置文件必须导出配置对象数组,不允许使用字符串。

迁移指南中提到过:

import js from "@eslint/js";

export default [
    js.configs.recommended,
    ...
];
© www.soinside.com 2019 - 2024. All rights reserved.