@@ -7,6 +7,10 @@ const rule = require('rules/no-useless-path-segments')
7
7
function runResolverTests ( resolver ) {
8
8
ruleTester . run ( `no-useless-path-segments (${ resolver } )` , rule , {
9
9
valid : [
10
+ // commonjs with default options
11
+ test ( { code : 'require("./../files/malformed.js")' } ) ,
12
+
13
+ // esmodule
10
14
test ( { code : 'import "./malformed.js"' } ) ,
11
15
test ( { code : 'import "./test-module"' } ) ,
12
16
test ( { code : 'import "./bar/"' } ) ,
@@ -16,6 +20,49 @@ function runResolverTests(resolver) {
16
20
] ,
17
21
18
22
invalid : [
23
+ // commonjs
24
+ test ( {
25
+ code : 'require("./../files/malformed.js")' ,
26
+ options : [ { commonjs : true } ] ,
27
+ errors : [ 'Useless path segments for "./../files/malformed.js", should be "../files/malformed.js"' ] ,
28
+ } ) ,
29
+ test ( {
30
+ code : 'require("./../files/malformed")' ,
31
+ options : [ { commonjs : true } ] ,
32
+ errors : [ 'Useless path segments for "./../files/malformed", should be "../files/malformed"' ] ,
33
+ } ) ,
34
+ test ( {
35
+ code : 'require("../files/malformed.js")' ,
36
+ options : [ { commonjs : true } ] ,
37
+ errors : [ 'Useless path segments for "../files/malformed.js", should be "./malformed.js"' ] ,
38
+ } ) ,
39
+ test ( {
40
+ code : 'require("../files/malformed")' ,
41
+ options : [ { commonjs : true } ] ,
42
+ errors : [ 'Useless path segments for "../files/malformed", should be "./malformed"' ] ,
43
+ } ) ,
44
+ test ( {
45
+ code : 'require("./test-module/")' ,
46
+ options : [ { commonjs : true } ] ,
47
+ errors : [ 'Useless path segments for "./test-module/", should be "./test-module"' ] ,
48
+ } ) ,
49
+ test ( {
50
+ code : 'require("./")' ,
51
+ options : [ { commonjs : true } ] ,
52
+ errors : [ 'Useless path segments for "./", should be "."' ] ,
53
+ } ) ,
54
+ test ( {
55
+ code : 'require("../")' ,
56
+ options : [ { commonjs : true } ] ,
57
+ errors : [ 'Useless path segments for "../", should be ".."' ] ,
58
+ } ) ,
59
+ test ( {
60
+ code : 'require("./deep//a")' ,
61
+ options : [ { commonjs : true } ] ,
62
+ errors : [ 'Useless path segments for "./deep//a", should be "./deep/a"' ] ,
63
+ } ) ,
64
+
65
+ // esmodule
19
66
test ( {
20
67
code : 'import "./../files/malformed.js"' ,
21
68
errors : [ 'Useless path segments for "./../files/malformed.js", should be "../files/malformed.js"' ] ,
0 commit comments