Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to deal with monorepos and import/no-extraneous-dependencies? #54

Closed
matthargett opened this issue May 11, 2019 · 2 comments
Closed
Labels

Comments

@matthargett
Copy link
Contributor

Ask your Question

I see this in our codebase with the current rulset:

C:\Users\matt\workspace\app\packages\home-ui\src\components\Home\__tests__\index.test.js
  6:1  error  'test-utils' should be listed in the project's dependencies. Run 'npm i -S test-utils' to add it  import/no-extraneous-dependencies

In this particular instance, 'test-utils' is another package in the monorepo located at C:\Users\matt\workspace\app\packages\test-utils. (Even so, it seems like a bug in eslint-plugin-import that they say to add a test dependency to regular dependencies instead of devDependencies.)

In our local eslintrc we have this override in our configuration to eliminate this class of false-positive warnings (and a few others) :

module.exports = {
  "extends": [
    "@sie/eslint-config-react-native-app",
  ],
  "overrides": [
    {
      "files": ["scripts/**/*.js", "**/*mock*/**/*.js", "**/__tests__/**/*.js"],
      "rules": {
        "global-require": "off",
        "import/no-extraneous-dependencies": "off",
        "one-var": "off",
      }
    }
  ],
}

eslint-plugin-import does have a way to specify package directories to accomodate monorepos, but I'm not sure if that could be used generically in this config package since monorepos structure can vary quite a bit.

Does someone have an idea how to use the packageDir option to this rule to not fire on this case? Would a PR to turn off this rule for test and mock directories be accepted?

@thymikee
Copy link
Member

thymikee commented May 11, 2019

We already disable this rule for test files:

'import/no-extraneous-dependencies': [
ERROR,
{
devDependencies: [
'**/__tests__/**/*.[jt]s?(x)',
'**/?(*.)+(spec|test).[tj]s?(x)',
],
},
],

Mind investigating why it still fires in your case? Maybe it's an ESLint bug in resolving globs on Windows?

@matthargett
Copy link
Contributor Author

This doesn't affect my current project, so I'm closing it now. If someone from my previous project(s) wants to re-open, they are free to do so :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants