Eslint-plugin-import: no-extraneous-dependencies should not complain when importing file from project name

Created on 4 Sep 2016  路  5Comments  路  Source: benmosher/eslint-plugin-import

Hi,
I have a React-native project named "MyProject".
When I import a file from 'MyProject/src/store' (which is valid with react-native, which is the way to load something from the root of the project), it complains.
I think it should detect that's the name of the current project, which is valid, and shouldn't throw an error.

screen shot 2016-09-04 at 10 48 26

Most helpful comment

I think this is a specific case of #479, see also #496.

All 5 comments

I think this is a specific case of #479, see also #496.

I think you may be able to solve this with the following resolver config:

// MyProject/.eslintrc.json
{
  "settings": {
    "import/resolver": {
      "node": { "paths": [ ".." ] }
    }
  }
}

or, failing that:

// MyProject/.eslintrc.js
exports.settings = {
  "import/resolver": {
    "node": { "paths": [ path.join(__dirname, "..") ] }
  }
}

Notably, I'm assuming your .eslintrc.{js,json,yml} is located in the MyProject folder. If not, adjust accordingly.

If the first way works, let me know and I'll update config/react-native.js.

Or if I can make the assumption that ESLint will be run from the project folder, could do path.resolve(".."), IIRC it resolves relative to CWD.

@alexmngn et. al., check out #626: @guzart implemented a React Native resolver. that should fix this, I think.

psst: added to import/order internal milestone to remember the react-native resolver when implementing the resolver-chooses-import-type API (#479)

Was this page helpful?
0 / 5 - 0 ratings