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

Rule proposal: no-native-addon-dependencies #808

Closed
silverwind opened this issue Aug 11, 2020 · 9 comments
Closed

Rule proposal: no-native-addon-dependencies #808

silverwind opened this issue Aug 11, 2020 · 9 comments
Labels

Comments

@silverwind
Copy link
Contributor

It is often desirable for portability and general stability to not have any native addons in the direct or indirect dependencies. If these cases could be detected reliably and fast, a rule could be created.

Fail

import 'node-sass'; /* error: module `node-sass` contains native addons */
import 'gulp-sass'; /* error: dependency `node-sass` of `gulp-sass` contains native addons */

Pass

import 'sass';
import 'gulp-dart-sass';
@papb
Copy link

papb commented Aug 11, 2020

Fantastic idea! How about no-platform-specific-imports?

@silverwind
Copy link
Contributor Author

I think I still prefer the name no-native-import. For example, I have a module that has platform-specific functionality while still being pure JS.

@papb
Copy link

papb commented Aug 11, 2020

@silverwind ah, yes, of course. You're right 🤦 actually now that you say it, I see it's clearly not unusual for cross-platform modules to require platform specific code (so that they accomodate for each platform). Sorry for the noise 😅

@sindresorhus
Copy link
Owner

I would prefer no-native-addon-dependencies. The "import" word would not work as it's about indirect dependencies too.

@silverwind
Copy link
Contributor Author

Terminology of "addons" seems good. It's also what Node uses in its docs.

@silverwind silverwind changed the title Rule Proposal: no-native-import Rule Proposal: no-native-addon-dependencies Aug 11, 2020
@silverwind
Copy link
Contributor Author

I do have to raise one argument against the rule: Some dependencies may never be imported and a linter rule would miss addons in those. For such cases a find node_modules -type f -name "*.node" would be more reliable.

@fisker
Copy link
Collaborator

fisker commented Aug 11, 2020

@silverwind
Copy link
Contributor Author

@fisker that's a simple denylist-based approach, the proposed rule would be more automatic in detection of native addons.

I actually think that unless there is a surefire way to detect native addons (require.resolve is not suitable because many modules have JS wrappers), the implementation would be too tricky and the proposal should probably be denied.

@sindresorhus sindresorhus changed the title Rule Proposal: no-native-addon-dependencies Rule proposal: no-native-addon-dependencies Sep 25, 2020
@sindresorhus
Copy link
Owner

I think this rule would be a better fit for https://github.com/mysticatea/eslint-plugin-node. I would recommend opening an issue there. The maintainer there might have some good idea on how to solve this.

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

No branches or pull requests

4 participants