Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
epidemian
GitHub Repository: epidemian/eslint-plugin-import
Path: blob/main/tests/src/rules/no-named-export.js
829 views
1
import { RuleTester } from 'eslint';
2
import { test } from '../utils';
3
4
const ruleTester = new RuleTester();
5
const rule = require('rules/no-named-export');
6
7
ruleTester.run('no-named-export', rule, {
8
valid: [
9
test({
10
code: 'export default function bar() {};',
11
}),
12
test({
13
code: 'let foo; export { foo as default }',
14
}),
15
test({
16
code: 'export default from "foo.js"',
17
parser: require.resolve('babel-eslint'),
18
}),
19
20
// no exports at all
21
test({
22
code: `import * as foo from './foo';`,
23
}),
24
test({
25
code: `import foo from './foo';`,
26
}),
27
test({
28
code: `import {default as foo} from './foo';`,
29
}),
30
],
31
invalid: [
32
test({
33
code: `
34
export const foo = 'foo';
35
export const bar = 'bar';
36
`,
37
errors: [{
38
type: 'ExportNamedDeclaration',
39
message: 'Named exports are not allowed.',
40
}, {
41
type: 'ExportNamedDeclaration',
42
message: 'Named exports are not allowed.',
43
}],
44
}),
45
test({
46
code: `
47
export const foo = 'foo';
48
export default bar;`,
49
errors: [{
50
type: 'ExportNamedDeclaration',
51
message: 'Named exports are not allowed.',
52
}],
53
}),
54
test({
55
code: `
56
export const foo = 'foo';
57
export function bar() {};
58
`,
59
errors: [{
60
type: 'ExportNamedDeclaration',
61
message: 'Named exports are not allowed.',
62
}, {
63
type: 'ExportNamedDeclaration',
64
message: 'Named exports are not allowed.',
65
}],
66
}),
67
test({
68
code: `export const foo = 'foo';`,
69
errors: [{
70
type: 'ExportNamedDeclaration',
71
message: 'Named exports are not allowed.',
72
}],
73
}),
74
test({
75
code: `
76
const foo = 'foo';
77
export { foo };
78
`,
79
errors: [{
80
type: 'ExportNamedDeclaration',
81
message: 'Named exports are not allowed.',
82
}],
83
}),
84
test({
85
code: `let foo, bar; export { foo, bar }`,
86
errors: [{
87
type: 'ExportNamedDeclaration',
88
message: 'Named exports are not allowed.',
89
}],
90
}),
91
test({
92
code: `export const { foo, bar } = item;`,
93
errors: [{
94
type: 'ExportNamedDeclaration',
95
message: 'Named exports are not allowed.',
96
}],
97
}),
98
test({
99
code: `export const { foo, bar: baz } = item;`,
100
errors: [{
101
type: 'ExportNamedDeclaration',
102
message: 'Named exports are not allowed.',
103
}],
104
}),
105
test({
106
code: `export const { foo: { bar, baz } } = item;`,
107
errors: [{
108
type: 'ExportNamedDeclaration',
109
message: 'Named exports are not allowed.',
110
}],
111
}),
112
test({
113
code: `
114
let item;
115
export const foo = item;
116
export { item };
117
`,
118
errors: [{
119
type: 'ExportNamedDeclaration',
120
message: 'Named exports are not allowed.',
121
}, {
122
type: 'ExportNamedDeclaration',
123
message: 'Named exports are not allowed.',
124
}],
125
}),
126
test({
127
code: `export * from './foo';`,
128
errors: [{
129
type: 'ExportAllDeclaration',
130
message: 'Named exports are not allowed.',
131
}],
132
}),
133
test({
134
code: `export const { foo } = { foo: "bar" };`,
135
errors: [{
136
type: 'ExportNamedDeclaration',
137
message: 'Named exports are not allowed.',
138
}],
139
}),
140
test({
141
code: `export const { foo: { bar } } = { foo: { bar: "baz" } };`,
142
errors: [{
143
type: 'ExportNamedDeclaration',
144
message: 'Named exports are not allowed.',
145
}],
146
}),
147
test({
148
code: 'export { a, b } from "foo.js"',
149
parser: require.resolve('babel-eslint'),
150
errors: [{
151
type: 'ExportNamedDeclaration',
152
message: 'Named exports are not allowed.',
153
}],
154
}),
155
test({
156
code: `export type UserId = number;`,
157
parser: require.resolve('babel-eslint'),
158
errors: [{
159
type: 'ExportNamedDeclaration',
160
message: 'Named exports are not allowed.',
161
}],
162
}),
163
test({
164
code: 'export foo from "foo.js"',
165
parser: require.resolve('babel-eslint'),
166
errors: [{
167
type: 'ExportNamedDeclaration',
168
message: 'Named exports are not allowed.',
169
}],
170
}),
171
test({
172
code: `export Memory, { MemoryValue } from './Memory'`,
173
parser: require.resolve('babel-eslint'),
174
errors: [{
175
type: 'ExportNamedDeclaration',
176
message: 'Named exports are not allowed.',
177
}],
178
}),
179
],
180
});
181
182