-
-
Notifications
You must be signed in to change notification settings - Fork 172
/
no-extraneous-require.js
98 lines (93 loc) · 2.64 KB
/
no-extraneous-require.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/**
* @author Toru Nagashima
* See LICENSE file in root directory for full license.
*/
"use strict"
const path = require("path")
const RuleTester = require("eslint").RuleTester
const rule = require("../../../lib/rules/no-extraneous-require")
/**
* Makes a file path to a fixture.
* @param {string} name - A name.
* @returns {string} A file path to a fixture.
*/
function fixture(name) {
return path.resolve(__dirname, "../../fixtures/no-extraneous", name)
}
const tester = new RuleTester({ env: { node: true } })
tester.run("no-extraneous-require", rule, {
valid: [
{
filename: fixture("dependencies/a.js"),
code: "$.require('bbb')",
},
{
filename: fixture("dependencies/a.js"),
code: "require('./bbb')",
},
{
filename: fixture("dependencies/a.js"),
code: "require(bbb)",
},
{
filename: fixture("dependencies/a.js"),
code: "require('aaa')",
},
{
filename: fixture("dependencies/a.js"),
code: "require('aaa/bbb')",
},
{
filename: fixture("dependencies/a.js"),
code: "require('@bbb/aaa')",
},
{
filename: fixture("dependencies/a.js"),
code: "require('@bbb/aaa/bbb')",
},
{
filename: fixture("devDependencies/a.js"),
code: "require('aaa')",
},
{
filename: fixture("peerDependencies/a.js"),
code: "require('aaa')",
},
{
filename: fixture("optionalDependencies/a.js"),
code: "require('aaa')",
},
// missing packages are warned by no-missing-require
{
filename: fixture("dependencies/a.js"),
code: "require('ccc')",
},
],
invalid: [
{
filename: fixture("dependencies/a.js"),
code: "require('bbb')",
errors: ['"bbb" is extraneous.'],
},
{
filename: fixture("devDependencies/a.js"),
code: "require('bbb')",
errors: ['"bbb" is extraneous.'],
},
{
filename: fixture("peerDependencies/a.js"),
code: "require('bbb')",
errors: ['"bbb" is extraneous.'],
},
{
filename: fixture("optionalDependencies/a.js"),
code: "require('bbb')",
errors: ['"bbb" is extraneous.'],
},
{
filename: fixture("dependencies/a.js"),
code: "require('b'+'bb')",
errors: ['"bbb" is extraneous.'],
},
],
})