Disallow imports of built-in Node.js modules without the node: prefix
You'll first need to install ESLint:
npm i eslint --save-devNext, install eslint-plugin-node-import:
npm install eslint-plugin-node-import --save-devExtend this plugin's recommended config:
const nodeImport = require('eslint-plugin-node-import');
module.exports = [
...nodeImport.configs["flat/recommended"],
// your config
]Add node-import to the plugins section of your configuration and configure the (only) rule under the rules section:
const nodeImport = require('eslint-plugin-node-import');
module.exports = [
{
plugins: {"node-import": nodeImport},
rules: {
"node-import/prefer-node-protocol": "error"
}
}
]Extend this plugin's recommended config:
{
"extends": ["plugin:node-import/recommended"]
}Add node-import to the plugins section of your .eslintrc configuration file and configure the (only) rule under the rules section:
{
"plugins": ["node-import"],
"rules": {
"node-import/prefer-node-protocol": 2
}
}💼 Configurations enabled in.
✅ Set in the recommended configuration.
🔧 Automatically fixable by the --fix CLI option.
| Name | Description | 💼 | 🔧 |
|---|---|---|---|
| prefer-node-protocol | Prefer using the node: protocol when importing Node.js builtin modules. |
✅ | 🔧 |
This plugin is a composite of two different custom ESLint rules:
- @alex-kinokon's
eslint-import-require-node-prefixfrom this GitHub Gist - Sindre Sorhus'
prefer-node-protocolfrom eslint-plugin-unicorn
© 2023 Nikita Karamov
Licensed under the ISC License
This project is hosted on GitHub: https://github.com/kytta/eslint-plugin-node-import.git