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 suggestion: prefer node: prefixed imports when possible #77

Closed
thernstig opened this issue Jan 10, 2023 · 6 comments · Fixed by #183
Closed

Rule suggestion: prefer node: prefixed imports when possible #77

thernstig opened this issue Jan 10, 2023 · 6 comments · Fixed by #183
Labels

Comments

@thernstig
Copy link

Older built-in Node modules such as fs now can be imported via either their name or node: + their name:

import fs from "fs";
import fs from "node:fs";

The prefixed versions are nice because they can't be overridden by user modules and are similarly formatted to to prefix-only modules such as node:test.

Suggestion: let's add a linter rule to enforce using them, with an auto-fixer.

(copied from mysticatea#344)

@thernstig thernstig changed the title Rule suggestion: prefer node: prefixed imports when possible #344 Rule suggestion: prefer node: prefixed imports when possible Jan 10, 2023
@aladdin-add
Copy link

yes, good to have. 👍

@voxpelli
Copy link
Member

There is a rule like this in eslint-plugin-unicorn, maybe we can ask to copy/lift that over? https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-node-protocol.md

@thernstig
Copy link
Author

thernstig commented Jan 20, 2023

A general question: Would such a rule be better in https://github.com/import-js/eslint-plugin-import?

I resorted to using eslint-plugin-unicorn for that rule right now, but it feels like a nice rule to have in here or https://github.com/import-js/eslint-plugin-import.

edit: Or maybe not as eslint-plugin-import is for generic ECMAScript Module imports both for the web and Node.js, so maybe such a rule is more suited here after all.

@gurgunday
Copy link

I think it should be here as well

@gurgunday
Copy link

Can we cut a release?

CC @aladdin-add

@aladdin-add
Copy link

We are in the development of the new major v17. I'll try to port it to v16 later.

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

Successfully merging a pull request may close this issue.

4 participants