-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
no-extraneous-packages should ignore invalid package names #340
Comments
Hi @novemberborn :) Do you have an example of a case where this is problematic for you? |
Sure. I maintain two Babel plugins which rewrite import statements: import files from 'files:../../content/**/*.md' I suppose this might be solved by writing a resolver for these Babel plugins (though I haven't checked whether this rule follows resolvers). However it seems to me that if we were to validate the package name (up to the first slash), then any invalid package name cannot be a valid dependency and is most likely to be use a custom resolver. In that case it won't be extraneous. |
It does, in part. I think a resolver here would help, though @benmosher is more knowledgeable on the subject ;) I'm wondering whether removing anything before a Any other ideas? |
I think my generic approach would be to reject anything that looks invalid. But maybe that's too generic.
Correct.
Apologies for to yet looking into how custom resolvers behave. At their simplest they could return a module path, but perhaps they could return other information for the import rules to use. E.g. |
I still haven't either, so no worries here :D
Well, in the case of this rule (haven't checked for the If you use the I'm 👍 with considered anything containing |
I think we should try and see where a path starts, and run everything before that through the |
I think maybe a general ignore pattern might be good. That, or a Babel resolver that knows how to speak to plugins. I'm thinking that might be a good future-proofing strategy to avoid continually re-implementing these and other Babel plugins as custom resolver behaviors. |
(Assuming that is technically feasible. It's been a while since I've looked at the Babel plugin API) |
You'd have to transpile the imports of each file, assuming you can determine the Babel config and the correct environment. Sounds tricky. |
It breaks with custom resolvers, see import-js/eslint-plugin-import#340
I think adding a pre-resolver ignore pattern check would solve this. You could add I like the simplicity of requiring the user to explicitly configure patterns for import overloading like this. |
I just updated and hit this issue. We use resolve.alias in webpack:
Any work around? |
@justin808 only |
I'm finally coming back to this and it appears that the Adding a resolver doesn't help since it doesn't influence how the source is treated. Extending that and using resolvers in all rules may be the best solution. As I wrote back in May #340 (comment):
|
@justin808 Yes: https://www.npmjs.com/package/eslint-import-resolver-webpack |
I'm confused - npm's validity for package names is irrelevant. Anything that's a valid directory name in Just because I can't have npm-installed a package name doesn't mean I didn't |
@novemberborn I have also arrived at what you've suggested: resolvers need to return additional metadata to classify import type. #479 is tracking this. I am hoping I will be able to spend some time on it next week. |
The proper way to handle this, I think, is the "ignore" setting and/or a custom resolver. Happy to reopen if that's not the case. |
Package names that are invalid in npm most likely use custom resolvers and won't be extraneous.
https://github.com/npm/validate-npm-package-name can be used to validate package names. I'm not sure whether legacy names should be treated as valid for the purpose of this issue.
The text was updated successfully, but these errors were encountered: