@@ -7,6 +7,10 @@ const rule = require('rules/no-useless-path-segments')
77function runResolverTests ( resolver ) {
88 ruleTester . run ( `no-useless-path-segments (${ resolver } )` , rule , {
99 valid : [
10+ // commonjs with default options
11+ test ( { code : 'require("./../files/malformed.js")' } ) ,
12+
13+ // esmodule
1014 test ( { code : 'import "./malformed.js"' } ) ,
1115 test ( { code : 'import "./test-module"' } ) ,
1216 test ( { code : 'import "./bar/"' } ) ,
@@ -16,6 +20,49 @@ function runResolverTests(resolver) {
1620 ] ,
1721
1822 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
1966 test ( {
2067 code : 'import "./../files/malformed.js"' ,
2168 errors : [ 'Useless path segments for "./../files/malformed.js", should be "../files/malformed.js"' ] ,
0 commit comments