forked from import-js/eslint-plugin-import
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextensions.js
121 lines (116 loc) · 3.06 KB
/
extensions.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
111
112
113
114
115
116
117
118
119
120
import { RuleTester } from 'eslint'
import rule from 'rules/extensions';
import { test } from '../utils';
const ruleTester = new RuleTester()
ruleTester.run('extensions', rule, {
valid: [
test({ code: 'import a from "a"' }),
test({ code: 'import dot from "./file.with.dot"' }),
test({
code: 'import a from "a/index.js"',
options: [ 'always' ]
}),
test({
code: 'import dot from "./file.with.dot.js"',
options: [ 'always' ]
}),
test({
code: [
'import a from "a"',
'import packageConfig from "./package.json"',
].join('\n'),
options: [ { json: 'always', js: 'never' } ]
}),
test({
code: [
'import lib from "./bar"',
'import component from "./bar.jsx"',
'import data from "./bar.json"'
].join('\n'),
options: [ 'never' ],
settings: { 'import/resolve': { 'extensions': [ '.js', '.jsx', '.json' ] } }
})
],
invalid: [
test({
code: 'import a from "a/index.js"',
errors: [ {
message: 'Unexpected use of file extension "js" for "a/index.js"',
line: 1,
column: 15
} ]
}),
test({
code: 'import a from "a"',
options: [ 'always' ],
errors: [ {
message: 'Missing file extension "js" for "a"',
line: 1,
column: 15
} ]
}),
test({
code: 'import dot from "./file.with.dot"',
options: [ "always" ],
errors: [
{
message: 'Missing file extension "js" for "./file.with.dot"',
line: 1,
column: 17
}
]
}),
test({
code: [
'import a from "a/index.js"',
'import packageConfig from "./package"',
].join('\n'),
options: [ { json: 'always', js: 'never' } ],
settings: { 'import/resolve': { 'extensions': [ '.js', '.json' ] } },
errors: [
{
message: 'Unexpected use of file extension "js" for "a/index.js"',
line: 1,
column: 15
},
{
message: 'Missing file extension "json" for "./package"',
line: 2,
column: 27
}
]
}),
test({
code: [
'import lib from "./bar.js"',
'import component from "./bar.jsx"',
'import data from "./bar.json"'
].join('\n'),
options: [ 'never' ],
settings: { 'import/resolve': { 'extensions': [ '.js', '.jsx', '.json' ] } },
errors: [
{
message: 'Unexpected use of file extension "js" for "./bar.js"',
line: 1,
column: 17
}
]
}),
test({
code: [
'import lib from "./bar.js"',
'import component from "./bar.jsx"',
'import data from "./bar.json"'
].join('\n'),
options: [ { json: 'always', js: 'never', jsx: 'never' } ],
settings: { 'import/resolve': { 'extensions': [ '.js', '.jsx', '.json' ] } },
errors: [
{
message: 'Unexpected use of file extension "js" for "./bar.js"',
line: 1,
column: 17
}
]
})
]
})