-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
no-unassigned-import.js
110 lines (106 loc) · 3.03 KB
/
no-unassigned-import.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
99
100
101
102
103
104
105
106
107
108
109
110
import { test } from '../utils'
import * as path from 'path'
import { RuleTester } from 'eslint'
const ruleTester = new RuleTester()
, rule = require('rules/no-unassigned-import')
const error = {
ruleId: 'no-unassigned-import',
message: 'Imported module should be assigned'
}
ruleTester.run('no-unassigned-import', rule, {
valid: [
test({ code: 'import _ from "lodash"'}),
test({ code: 'import _, {foo} from "lodash"'}),
test({ code: 'import _, {foo as bar} from "lodash"'}),
test({ code: 'import {foo as bar} from "lodash"'}),
test({ code: 'import * as _ from "lodash"'}),
test({ code: 'import _ from "./"'}),
test({ code: 'const _ = require("lodash")'}),
test({ code: 'const {foo} = require("lodash")'}),
test({ code: 'const {foo: bar} = require("lodash")'}),
test({ code: 'const [a, b] = require("lodash")'}),
test({ code: 'const _ = require("lodash")'}),
test({ code: 'const _ = require("./")'}),
test({ code: 'foo(require("lodash"))'}),
test({ code: 'require("lodash").foo'}),
test({ code: 'require("lodash").foo()'}),
test({ code: 'require("lodash")()'}),
test({
code: 'import "app.css"',
options: [{ 'allow': ['**/*.css'] }],
}),
test({
code: 'import "app.css";',
options: [{ 'allow': ['*.css'] }],
}),
test({
code: 'import "./app.css"',
options: [{ 'allow': ['**/*.css'] }],
}),
test({
code: 'import "foo/bar"',
options: [{ 'allow': ['foo/**'] }],
}),
test({
code: 'import "foo/bar"',
options: [{ 'allow': ['foo/bar'] }],
}),
test({
code: 'import "../dir/app.css"',
options: [{ 'allow': ['**/*.css'] }],
}),
test({
code: 'import "../dir/app.js"',
options: [{ 'allow': ['**/dir/**'] }],
}),
test({
code: 'require("./app.css")',
options: [{ 'allow': ['**/*.css'] }],
}),
test({
code: 'import "babel-register"',
options: [{ 'allow': ['babel-register'] }],
}),
test({
code: 'import "./styles/app.css"',
options: [{ 'allow': ['src/styles/**'] }],
filename: path.join(process.cwd(), 'src/app.js'),
}),
test({
code: 'import "../scripts/register.js"',
options: [{ 'allow': ['src/styles/**', '**/scripts/*.js'] }],
filename: path.join(process.cwd(), 'src/app.js'),
}),
],
invalid: [
test({
code: 'import "lodash"',
errors: [error],
}),
test({
code: 'require("lodash")',
errors: [error],
}),
test({
code: 'import "./app.css"',
options: [{ 'allow': ['**/*.js'] }],
errors: [error],
}),
test({
code: 'import "./app.css"',
options: [{ 'allow': ['**/dir/**'] }],
errors: [error],
}),
test({
code: 'require("./app.css")',
options: [{ 'allow': ['**/*.js'] }],
errors: [error],
}),
test({
code: 'import "./styles/app.css"',
options: [{ 'allow': ['styles/*.css'] }],
filename: path.join(process.cwd(), 'src/app.js'),
errors: [error],
}),
],
})