Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
epidemian
GitHub Repository: epidemian/eslint-plugin-import
Path: blob/main/tests/src/rules/no-unassigned-import.js
829 views
1
import { test } from '../utils';
2
import * as path from 'path';
3
4
import { RuleTester } from 'eslint';
5
6
const ruleTester = new RuleTester();
7
const rule = require('rules/no-unassigned-import');
8
9
const error = {
10
message: 'Imported module should be assigned',
11
};
12
13
ruleTester.run('no-unassigned-import', rule, {
14
valid: [
15
test({ code: 'import _ from "lodash"' }),
16
test({ code: 'import _, {foo} from "lodash"' }),
17
test({ code: 'import _, {foo as bar} from "lodash"' }),
18
test({ code: 'import {foo as bar} from "lodash"' }),
19
test({ code: 'import * as _ from "lodash"' }),
20
test({ code: 'import _ from "./"' }),
21
test({ code: 'const _ = require("lodash")' }),
22
test({ code: 'const {foo} = require("lodash")' }),
23
test({ code: 'const {foo: bar} = require("lodash")' }),
24
test({ code: 'const [a, b] = require("lodash")' }),
25
test({ code: 'const _ = require("./")' }),
26
test({ code: 'foo(require("lodash"))' }),
27
test({ code: 'require("lodash").foo' }),
28
test({ code: 'require("lodash").foo()' }),
29
test({ code: 'require("lodash")()' }),
30
test({
31
code: 'import "app.css"',
32
options: [{ 'allow': ['**/*.css'] }],
33
}),
34
test({
35
code: 'import "app.css";',
36
options: [{ 'allow': ['*.css'] }],
37
}),
38
test({
39
code: 'import "./app.css"',
40
options: [{ 'allow': ['**/*.css'] }],
41
}),
42
test({
43
code: 'import "foo/bar"',
44
options: [{ 'allow': ['foo/**'] }],
45
}),
46
test({
47
code: 'import "foo/bar"',
48
options: [{ 'allow': ['foo/bar'] }],
49
}),
50
test({
51
code: 'import "../dir/app.css"',
52
options: [{ 'allow': ['**/*.css'] }],
53
}),
54
test({
55
code: 'import "../dir/app.js"',
56
options: [{ 'allow': ['**/dir/**'] }],
57
}),
58
test({
59
code: 'require("./app.css")',
60
options: [{ 'allow': ['**/*.css'] }],
61
}),
62
test({
63
code: 'import "babel-register"',
64
options: [{ 'allow': ['babel-register'] }],
65
}),
66
test({
67
code: 'import "./styles/app.css"',
68
options: [{ 'allow': ['src/styles/**'] }],
69
filename: path.join(process.cwd(), 'src/app.js'),
70
}),
71
test({
72
code: 'import "../scripts/register.js"',
73
options: [{ 'allow': ['src/styles/**', '**/scripts/*.js'] }],
74
filename: path.join(process.cwd(), 'src/app.js'),
75
}),
76
],
77
invalid: [
78
test({
79
code: 'import "lodash"',
80
errors: [error],
81
}),
82
test({
83
code: 'require("lodash")',
84
errors: [error],
85
}),
86
test({
87
code: 'import "./app.css"',
88
options: [{ 'allow': ['**/*.js'] }],
89
errors: [error],
90
}),
91
test({
92
code: 'import "./app.css"',
93
options: [{ 'allow': ['**/dir/**'] }],
94
errors: [error],
95
}),
96
test({
97
code: 'require("./app.css")',
98
options: [{ 'allow': ['**/*.js'] }],
99
errors: [error],
100
}),
101
test({
102
code: 'import "./styles/app.css"',
103
options: [{ 'allow': ['styles/*.css'] }],
104
filename: path.join(process.cwd(), 'src/app.js'),
105
errors: [error],
106
}),
107
],
108
});
109
110