如何在创建React App中创建绝对路径

时间:2019-10-07 06:26:08

标签: javascript reactjs create-react-app eslint

我已经将eslint配置配置为使用绝对路径。我使用了本手册https://dev.to/oliverandrich/absolute-imports-with-create-react-app-and-vscode-ihn。一切运行正常,但是eslint显示错误“绝对导入应该在相对import.eslint(import / first)之前”。我试图用谷歌搜索,但没有成功。有什么建议吗?

这是我的eslint配置:

{
  "parser": "babel-eslint",
  "parserOptions": {
    "sourceType": "module",
    "allowImportExportEverywhere": true
  },
  "extends": ["airbnb","react-app", "plugin:import/errors", "plugin:import/warnings"],
  "settings": {
    "import/resolver": {
      "node": {
        "moduleDirectory": ["node_modules", "src/"]
      }
    }
  },
  "env": {
    "jest/globals": true,
    "browser": true,
    "node": true
  },
  "rules": {
    "arrow-parens": [
      "off"
    ],
    "compat/compat": "error",
    "consistent-return": "off",
    "comma-dangle": "off",
    "flowtype-errors/show-errors": "error",
    "generator-star-spacing": "off",
    "import/no-unresolved": "error",
    "import/no-extraneous-dependencies": "off",
    "no-console": "off",
    "no-use-before-define": "off",
    "no-multi-assign": "off",
    "no-underscore-dangle": "off",
    "promise/param-names": "error",
    "react/no-array-index-key": "off",
    "promise/catch-or-return": "error",
    "promise/no-native": "off",
    "react/sort-comp": [
      "error",
      {
        "order": [
          "type-annotations",
          "static-methods",
          "lifecycle",
          "everything-else",
          "render"
        ]
      }
    ],
    "react/jsx-no-bind": "off",
    "react/jsx-filename-extension": [
      "error",
      {
        "extensions": [
          ".js",
          ".jsx"
        ]
      }
    ],
    "react/prefer-stateless-function": "off",
    "react/forbid-prop-types": [
      "error",
      {
        "forbid": []
      }
    ],
    "no-useless-escape": "off",
    "no-confusing-arrow": "off",
    "no-plusplus": "off",
    "jest/no-disabled-tests": "warn",
    "jest/no-focused-tests": "error",
    "jest/no-identical-title": "error",
    "jest/valid-expect": "error"
  },
  "plugins": [
    "flowtype",
    "flowtype-errors",
    "import",
    "promise",
    "compat",
    "react",
    "jest"
  ]
}

0 个答案:

没有答案