QuiiBz / sherif

Opinionated, zero-config linter for JavaScript monorepos
MIT License
915 stars 14 forks source link

[Feature Request] - Missing dependencies #87

Open Netail opened 3 months ago

Netail commented 3 months ago

Summary

When working in a mono repo, you can import packages from the node_modules which are used by other packages within the mono repo, but not listed in the dependency list of the package you are working in. It might be nice to give the user a heads up to include the dependency in their dependency list too.

Example

{
  "name": "package-a",
  "dependencies": {
    "react": "^18"
  }
}
{
  "name": "package-b",
  "dependencies": {
    "react": "^18"
  }
}
{
  "name": "package-c",
  "dependencies": {}
}

As both package a & b use react, the react is installed in the root node_modules, thus allowing it to be imported by package c too. When react is also used in the source code of package c, it should be listed in the dependency or dev dependency list

QuiiBz commented 3 months ago

That's a cool idea, but I'm not sure how we could reliably detect if another package is using a dependency that isn't specified in its own dependencies / devDependencies. At a first glance, we would have to analyze the source code for all packages to detect any import statements, which might be expensive.

Do you have any other idea in mind?

Netail commented 3 months ago

That's a good question, to which I do not have the answer to :(

alSergey commented 2 months ago

eslint-plugin-import has a similar rule.

Netail commented 2 months ago

eslint-plugin-import has a similar rule.

Does it work with monorepo's?

alSergey commented 2 months ago

Yes, it looks for dependencies in the nearest package.json file. I use it in my monorepo.