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

Add allow option to no-nodejs-modules #452

Closed
ljharb opened this issue Jul 24, 2016 · 13 comments · Fixed by #509
Closed

Add allow option to no-nodejs-modules #452

ljharb opened this issue Jul 24, 2016 · 13 comments · Fixed by #509

Comments

@ljharb
Copy link
Member

ljharb commented Jul 24, 2016

The no-nodejs-modules rule is very useful, but some modules are fine to import - like events - due to a good browserify shim.

I'd like the ability to add exceptions to this rule.

@jfmengels
Copy link
Collaborator

Wouldn't be very hard to implement. But does this occur very often? If not, a eslint-disable comment could be the best option.

@benmosher
Copy link
Member

I had the same initial gut reaction as @jfmengels, though that said I can imagine making a browserify shared config with this rule configured with a default whitelist. (crypto comes to mind as well as one that works fine in the browser.)

Also, I'd move to call the option whitelist, barring precedent from other rules (in this plugin or elsewhere).

Would be an easy PR for someone. @jfmengels do you think it hurts to have this?

@jfmengels
Copy link
Collaborator

jfmengels commented Jul 25, 2016

Just getting the feeling that for a lot of rules there are a lot of requests to have exceptions. It's a recurring theme.
But no, I think it's fine here.

👍 for whitelist

@benmosher
Copy link
Member

Yeah, I am getting that feeling too, in general.

This case is explicit, pragmatic, and obvious, though.

I can imagine one could argue for an eslint-plugin-browserify to handle this, maybe, but that would be on the pedantic side.

(linked because a quick web search found it to exist, by the law of npm that there is an npm package for every combination of two popular projects that support plugins, lol. 😎)

@benmosher benmosher changed the title Add exceptions option to no-nodejs-modules Add whitelist option to no-nodejs-modules Jul 25, 2016
@benmosher
Copy link
Member

Updated title to match discussion, @ljharb feel free to voice disagreement, just wanted to make sure possible PR submitters don't miss the discussion.

@ljharb
Copy link
Member Author

ljharb commented Jul 25, 2016

I'd prefer a more neutral term that lacks the connotation of "whitelist".

@benmosher
Copy link
Member

Fair enough. allow?

@benmosher benmosher changed the title Add whitelist option to no-nodejs-modules Add allow option to no-nodejs-modules Jul 25, 2016
@ljharb
Copy link
Member Author

ljharb commented Jul 25, 2016

Sounds great! Fwiw, this isn't just for browserify, anyone who'd set up a custom alias for bundling, in webpacking as well, may still want this ability.

@jfmengels jfmengels self-assigned this Jul 26, 2016
@benmosher benmosher added this to the 1.13.0 milestone Jul 27, 2016
@benmosher benmosher modified the milestones: soon, 1.13.0 Aug 11, 2016
@graingert
Copy link
Contributor

This should allow by default anything in node-libs-browser

It would be good to have presets for this, based on the table at https://github.com/webpack/node-libs-browser:

hasImplementation: true (anything with a value for has implementation)
hasMock: false (anything with a value for has mock)

@benmosher
Copy link
Member

@graingert certainly there should be an easy way to configure that, i.e. allow: 'node-libs-browser' though I think it might should ignore everything by default. Maybe not, though, if the majority use case is for browser-bundling.

@graingert
Copy link
Contributor

might should maybe not? I don't understand :(

@benmosher
Copy link
Member

restatement: it's a breaking change not to ignore everything by default, but I think you're probably right in that in v2 it should default to allowing node-libs-browser through, for convenience's sake.

@benmosher
Copy link
Member

added the semver-major label so I remember to make an item to update the default behavior over in v2

benmosher pushed a commit that referenced this issue Aug 23, 2016
* Add `allow` option to `no-nodejs-modules` rule (fixes #452)

* Add test case

* Fix not working in Node v4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment