Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
epidemian
GitHub Repository: epidemian/eslint-plugin-import
Path: blob/main/tests/src/rules/exports-last.js
829 views
1
import { test } from '../utils';
2
3
import { RuleTester } from 'eslint';
4
import rule from 'rules/exports-last';
5
6
const ruleTester = new RuleTester();
7
8
const error = type => ({
9
message: 'Export statements should appear at the end of the file',
10
type,
11
});
12
13
ruleTester.run('exports-last', rule, {
14
valid: [
15
// Empty file
16
test({
17
code: '// comment',
18
}),
19
test({
20
// No exports
21
code: `
22
const foo = 'bar'
23
const bar = 'baz'
24
`,
25
}),
26
test({
27
code: `
28
const foo = 'bar'
29
export {foo}
30
`,
31
}),
32
test({
33
code: `
34
const foo = 'bar'
35
export default foo
36
`,
37
}),
38
// Only exports
39
test({
40
code: `
41
export default foo
42
export const bar = true
43
`,
44
}),
45
test({
46
code: `
47
const foo = 'bar'
48
export default foo
49
export const bar = true
50
`,
51
}),
52
// Multiline export
53
test({
54
code: `
55
const foo = 'bar'
56
export default function bar () {
57
const very = 'multiline'
58
}
59
export const baz = true
60
`,
61
}),
62
// Many exports
63
test({
64
code: `
65
const foo = 'bar'
66
export default foo
67
export const so = 'many'
68
export const exports = ':)'
69
export const i = 'cant'
70
export const even = 'count'
71
export const how = 'many'
72
`,
73
}),
74
// Export all
75
test({
76
code: `
77
export * from './foo'
78
`,
79
}),
80
],
81
invalid: [
82
// Default export before variable declaration
83
test({
84
code: `
85
export default 'bar'
86
const bar = true
87
`,
88
errors: [error('ExportDefaultDeclaration')],
89
}),
90
// Named export before variable declaration
91
test({
92
code: `
93
export const foo = 'bar'
94
const bar = true
95
`,
96
errors: [error('ExportNamedDeclaration')],
97
}),
98
// Export all before variable declaration
99
test({
100
code: `
101
export * from './foo'
102
const bar = true
103
`,
104
errors: [error('ExportAllDeclaration')],
105
}),
106
// Many exports arround variable declaration
107
test({
108
code: `
109
export default 'such foo many bar'
110
export const so = 'many'
111
const foo = 'bar'
112
export const exports = ':)'
113
export const i = 'cant'
114
export const even = 'count'
115
export const how = 'many'
116
`,
117
errors: [
118
error('ExportDefaultDeclaration'),
119
error('ExportNamedDeclaration'),
120
],
121
}),
122
],
123
});
124
125