最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How I can change eslint resolve settings - Stack Overflow

programmeradmin1浏览0评论

I have project where I use webpack, eslint. Through webpack.config I set to resolve index and Index files. Everything works, except that eslint throws errors import/no-unresolved and import/extensions, it doesn't know, that beside of index, now it should resolve Index files too (import Index from ./components, where in ./components have file Index.jsx). My settings below.

// .eslintrc
{
  "extends": "airbnb",
  "env": { "browser": true },
  "rules": {
    "no-restricted-syntax": "off",
    "no-continue": "off",
    "no-plusplus": "off",
    "react/prop-types": "off",
    "no-underscore-dangle": "off",
    "no-param-reassign": "off",
    "class-methods-use-this": "off"
  }
}

// package.json
// ...
 "devDependencies": {
    // ...
    "eslint": "^4.19.1",
    "eslint-config-airbnb": "^16.1.0",
    "eslint-plugin-import": "^2.10.0",
    "eslint-plugin-jsx-a11y": "^6.0.3",
    "eslint-plugin-react": "^7.7.0",
    // ...
 }
// ...

I have project where I use webpack, eslint. Through webpack.config I set to resolve index and Index files. Everything works, except that eslint throws errors import/no-unresolved and import/extensions, it doesn't know, that beside of index, now it should resolve Index files too (import Index from ./components, where in ./components have file Index.jsx). My settings below.

// .eslintrc
{
  "extends": "airbnb",
  "env": { "browser": true },
  "rules": {
    "no-restricted-syntax": "off",
    "no-continue": "off",
    "no-plusplus": "off",
    "react/prop-types": "off",
    "no-underscore-dangle": "off",
    "no-param-reassign": "off",
    "class-methods-use-this": "off"
  }
}

// package.json
// ...
 "devDependencies": {
    // ...
    "eslint": "^4.19.1",
    "eslint-config-airbnb": "^16.1.0",
    "eslint-plugin-import": "^2.10.0",
    "eslint-plugin-jsx-a11y": "^6.0.3",
    "eslint-plugin-react": "^7.7.0",
    // ...
 }
// ...

Share Improve this question edited Apr 26, 2018 at 12:33 Rami Chasygov asked Apr 26, 2018 at 11:04 Rami ChasygovRami Chasygov 2,7849 gold badges26 silver badges39 bronze badges 2
  • 1 don't forget to mark the answer as correct if it is. – Wayrex Commented Aug 7, 2019 at 15:54
  • 1 "react/prop-types": "off" is a really bad idea. – Johannes P. Commented May 7, 2020 at 10:30
Add a comment  | 

1 Answer 1

Reset to default 14

Try installing eslint-import-resolver-webpack and adding this to your .eslintrc:

"settings": {
  "import/resolver": "webpack"
}

Or adding the source folder from which it will resolve the dependencies; something like this:

settings: {
    'import/resolver': {
        node: {
            paths: [path.resolve(__dirname, 'src')],
        },
    },
}

Resolver documentation: https://github.com/benmosher/eslint-plugin-import/blob/master/README.md#resolvers

发布评论

评论列表(0)

  1. 暂无评论