Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
epidemian
GitHub Repository: epidemian/eslint-plugin-import
Path: blob/main/tests/src/rules/no-nodejs-modules.js
829 views
1
import { test } from '../utils';
2
3
import { RuleTester } from 'eslint';
4
5
const ruleTester = new RuleTester();
6
const rule = require('rules/no-nodejs-modules');
7
8
const error = message => ({
9
message,
10
});
11
12
ruleTester.run('no-nodejs-modules', rule, {
13
valid: [
14
test({ code: 'import _ from "lodash"' }),
15
test({ code: 'import find from "lodash.find"' }),
16
test({ code: 'import foo from "./foo"' }),
17
test({ code: 'import foo from "../foo"' }),
18
test({ code: 'import foo from "foo"' }),
19
test({ code: 'import foo from "./"' }),
20
test({ code: 'import foo from "@scope/foo"' }),
21
test({ code: 'var _ = require("lodash")' }),
22
test({ code: 'var find = require("lodash.find")' }),
23
test({ code: 'var foo = require("./foo")' }),
24
test({ code: 'var foo = require("../foo")' }),
25
test({ code: 'var foo = require("foo")' }),
26
test({ code: 'var foo = require("./")' }),
27
test({ code: 'var foo = require("@scope/foo")' }),
28
test({
29
code: 'import events from "events"',
30
options: [{
31
allow: ['events'],
32
}],
33
}),
34
test({
35
code: 'import path from "path"',
36
options: [{
37
allow: ['path'],
38
}],
39
}),
40
test({
41
code: 'var events = require("events")',
42
options: [{
43
allow: ['events'],
44
}],
45
}),
46
test({
47
code: 'var path = require("path")',
48
options: [{
49
allow: ['path'],
50
}],
51
}),
52
test({
53
code: 'import path from "path";import events from "events"',
54
options: [{
55
allow: ['path', 'events'],
56
}],
57
}),
58
],
59
invalid: [
60
test({
61
code: 'import path from "path"',
62
errors: [error('Do not import Node.js builtin module "path"')],
63
}),
64
test({
65
code: 'import fs from "fs"',
66
errors: [error('Do not import Node.js builtin module "fs"')],
67
}),
68
test({
69
code: 'var path = require("path")',
70
errors: [error('Do not import Node.js builtin module "path"')],
71
}),
72
test({
73
code: 'var fs = require("fs")',
74
errors: [error('Do not import Node.js builtin module "fs"')],
75
}),
76
test({
77
code: 'import fs from "fs"',
78
options: [{
79
allow: ['path'],
80
}],
81
errors: [error('Do not import Node.js builtin module "fs"')],
82
}),
83
],
84
});
85
86