首页 > 解决方案 > 进口应按字母顺序排序错误

问题描述

我的文件中有以下导入:

import axios from "axios";
import lodash from "lodash";
import PropTypes from "prop-types";
import React from "react";
import renderInCustomHtmlTag from "react-render-custom-html-tag";

我使用的是 v5.9.0,但由于某种原因,我收到第 3 行的错误,即使它似乎是按字母顺序排列的。

我的eslint如下:

{
  "env": {
    "browser": true,
    "commonjs": true,
    "es6" : true,
    "jquery": true,
    "node": true
  },
  "extends": [
    "eslint:all",
    "plugin:react/recommended"
  ],
  "globals": {
    "$cgx": true
  },
  "parser": "babel-eslint",
  "parserOptions": {
    "ecmaFeatures": {
      "jsx": true
    },
    "sourceType": "module"
  },
  "plugins": [
    "import",
    "jsx-a11y",
    "react"

  ],
  "rules": {
    "indent": ["error", 2],
    "max-len": [
      "error",
      {
        "code": 120
      }
    ]
  }
}

标签: node.jseslint

解决方案


问题可能是大写字母。似乎是因为它们具有较低的 ASCII 值 A = 65,a = 97。

https://eslint.org/docs/2.0.0/rules/sort-imports


推荐阅读