ESLint - 别名设置

Anc*_*nek 6 javascript eslint

所以我在我的 webpack 配置中使用别名,我有eslint关于no-extraneous-dependencies等的警告。

所以我安装eslint-plugin-import沿eslint-import-resolver-alias和配置我的.eslintrc这样的文件:

{
  "parser": "babel-eslint",
  "extends": "airbnb",
  "env": {
    "browser": true,
    "es6": true,
    "node": true,
    "jest": true
  },
  "parserOptions": {
    "ecmaVersion": 6,
    "sourceType": "module",
    "ecmaFeatures": {
      "defaultParams": true
    }
  },
  "rules": {
    "react/jsx-filename-extension": 0,
    "react/sort-comp": 0,
    "linebreak-style": 0,
    "prefer-arrow-callback": 0,
    "consistent-return": 0,
    "func-names": 0,
  },
  "settings": {
    "import/resolver": {
      "alias": [
        // I have my actions folder in ./shared/actions
        ["Actions", "./shared/actions"]
      ]
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

我的 linter 无法使用此settings选项。我错过了什么?

小智 2

问题必须出在你的相对路径上

"./shared/actions"
Run Code Online (Sandbox Code Playgroud)

尝试将其更改为

"../shared/actions"
Run Code Online (Sandbox Code Playgroud)

如果这不起作用,请尝试绝对路径并从那里开始。

基本上,根目录/当前工作目录,并不是你想象的那样......