eslint-plugin-simple-import-sort 排序错误

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

下面是我的 .eslint.js。我试图定义 React 应该是我的 .js 文件中的第一个导入。但是,即使反应位于文件顶部,我也会抛出以下错误?

我遵循了一些在线指南,但看不出哪里出错了?

Line 1:1:  Run autofix to sort these imports!  simple-import-sort/imports
import React, { useRef, useState } from "react";
module.exports = {
    env: {
      ...
    },
    extends: [
      ...
    ],
    parser: "@babel/eslint-parser",
    parserOptions: {
        ecmaFeatures: {
            jsx: true
        },
        ecmaVersion: 6,
        sourceType: "module",
        requireConfigFile: false,
        "babelOptions": {
            "presets": ["@babel/preset-react"]
        },
        "sourceType": "module"
    },
    plugins: [
        "react",
        "import",
        "simple-import-sort"
    ],
    root: true,
    rules: {
        ...
        "simple-import-sort/imports": "error",
        "simple-import-sort/exports": "error"
    },
    settings: {
        react: {
            version: "detect"
        }
    },
    "overrides": [
        {
            "files": [
                "*.js",
                "*.jsx",
            ],
            "rules": {
                "simple-import-sort/imports": [
                    "error",
                    {
                        "groups": [
                            // Packages `react` related packages come first.
                            ["^react"],
                        ]
                    }
                ]
            }
        }
    ]

};
    

javascript reactjs eslint
1个回答
0
投票

这个问题解决了吗?在我的例子中,从 VS Code 运行“ESLint:修复 - 所有可自动修复的问题”会导致在修复错误的导入语句之后添加一个空白。

© www.soinside.com 2019 - 2024. All rights reserved.