-
-
Notifications
You must be signed in to change notification settings - Fork 41
no-extraneous-dependencies should not report the package itself #305
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
Comments
Is importing the package itself a good practice? Isn't it a circle dependency? |
Yep indeed. But it happens in my test files: they are importing the package to test it. So the example is more like this: index.js: export const answer = 42; tests/index.test.js: import { answer } from "package-name";
if (answer !== 42) {
throw new Error("answer should be 42");
} |
I believe you should disable |
My goal with this rule is mainly to ensure my dependencies are properly listed in the package.json. So I could disable it entirely for test files. But ideally I could also use it to ensure my devDependencies are listed. So I would like an option like allowSelfImport that I would set to true only in test files. Is that something that make sense? |
That could make sense, but I need to think about it more and discuss with others. |
Can't you add it as internal devDependency? Like I did in https://github.com/salsita/node-pg-migrate/blob/main/package.json#L114 |
That would likely fix my issue indeed 🤔 I'll try this (By the way I think |
By the way, I'd prefer |
In the end I've added the package name into my devDependencies as follow: {
"name": "package-name",
"devDependencies": {
"package-name": "./"
}
} For me it's a good enough way to be able to reference the package from test files while keeping Thanks to the quick responses and feedback. |
Can this issue be closed then? |
Can this be reopened? I like this rule, but it’s also the one I have to disable very often because of this issue. It looks easy to fix too. I’ll gladly provide a PR if this is accepted.
This was already brought up, but I think it’s a great practice to import a package using its name in test files. This tests whether the package exports are correct.
I agree they should have different rules. For tests I allow
That might work, but it would only be a workaround for this issue. |
Hi, @remcohaszing. Great to see you here! A PR resolving this issue would be appreciated for sure! ❤️ |
Allow packages to import themselves via the `package.json` exports field. If a package tries this, but the exports field is not defined, a new message is reported. Closes un-ts#305
The following
package.json
And
index.js
:Actual
import-x/no-extraneous-dependencies
rule reports an error with the following message.'package-name' should be listed in the project's dependencies. Run 'npm i -S package-name' to add it
Expected
import-x/no-extraneous-dependencies
remains silent because the package can import itself.The text was updated successfully, but these errors were encountered: