Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
epidemian
GitHub Repository: epidemian/eslint-plugin-import
Path: blob/main/src/rules/no-nodejs-modules.js
829 views
1
import importType from '../core/importType';
2
import moduleVisitor from 'eslint-module-utils/moduleVisitor';
3
import docsUrl from '../docsUrl';
4
5
function reportIfMissing(context, node, allowed, name) {
6
if (allowed.indexOf(name) === -1 && importType(name, context) === 'builtin') {
7
context.report(node, 'Do not import Node.js builtin module "' + name + '"');
8
}
9
}
10
11
module.exports = {
12
meta: {
13
type: 'suggestion',
14
docs: {
15
url: docsUrl('no-nodejs-modules'),
16
},
17
schema: [
18
{
19
type: 'object',
20
properties: {
21
allow: {
22
type: 'array',
23
uniqueItems: true,
24
items: {
25
type: 'string',
26
},
27
},
28
},
29
additionalProperties: false,
30
},
31
],
32
},
33
34
create(context) {
35
const options = context.options[0] || {};
36
const allowed = options.allow || [];
37
38
return moduleVisitor((source, node) => {
39
reportIfMissing(context, node, allowed, source.value);
40
}, { commonjs: true });
41
},
42
};
43
44