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

no-unresolved rule should not report for optionalDependencies #812

Open
sindresorhus opened this issue Apr 27, 2017 · 3 comments
Open

no-unresolved rule should not report for optionalDependencies #812

sindresorhus opened this issue Apr 27, 2017 · 3 comments

Comments

@sindresorhus
Copy link

Imported packages that are defined in optionalDependencies in package.json are optional and should not cause a violation.

@ljharb
Copy link
Member

ljharb commented Apr 27, 2017

they're "optional" in that the overarching install won't fail if their installation fails; that's not the same thing as optional.

no-unresolved also doesn't skip devDependencies when NODE_ENV is production - its purpose is to warn when a require wouldn't work. If you're requiring an optional dep, just like you'd already have to wrap it in a try/catch, you'd also need to add an eslint override.

In the linked use case, certainly the "windows.js" entry point might be optionally required, but unless the dependency is present, it'd fail at runtime.

The only thing I can think of that might possibly make sense here is an explicit option to skip optionalDependencies, or, an explicit "exceptions" array - but in general I think that conditional requires and optional deps run counter to the purpose of the rule.

@sindresorhus
Copy link
Author

The point is that if I put a dependency in optionalDependencies, I'm explicitly indicating I want to handle it myself. I think this plugin should respect that, at least through an option.

@abcdapply
Copy link

I have a Jest test file that uses the redux-mock-store package, which gets installed with --save-dev. I get a false positive for import/no-unresolved and import/extensions

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

No branches or pull requests

3 participants