]>
git.proxmox.com Git - pve-eslint.git/blob - eslint/tests/lib/rules/newline-per-chained-call.js
a0eefd2e790e4e23b676b0336b6554958657f658
2 * @fileoverview Tests for newline-per-chained-call rule.
3 * @author Rajendra Patil
8 //------------------------------------------------------------------------------
10 //------------------------------------------------------------------------------
12 const rule
= require ( "../../../lib/rules/newline-per-chained-call" ),
13 { RuleTester
} = require ( "../../../lib/rule-tester" );
15 const ruleTester
= new RuleTester ();
17 ruleTester
. run ( "newline-per-chained-call" , rule
, {
18 valid
: [ "_ \n .chain({}) \n .map(foo) \n .filter(bar) \n .value();" , "a.b.c.d.e.f" , "a() \n .b() \n .c \n .e" , "var a = m1.m2(); var b = m1.m2(); \n var c = m1.m2()" , "var a = m1() \n .m2();" , "var a = m1();" , "a() \n .b().c.e.d()" , "a().b().c.e.d()" , "a.b.c.e.d()" , "var a = window \n .location \n .href \n .match(/(^[^#]*)/)[0];" , "var a = window['location'] \n .href \n .match(/(^[^#]*)/)[0];" , "var a = window['location'].href.match(/(^[^#]*)/)[0];" , {
19 code
: "var a = m1().m2.m3();" ,
21 ignoreChainWithDepth
: 3
24 code
: "var a = m1().m2.m3().m4.m5().m6.m7().m8;" ,
26 ignoreChainWithDepth
: 8
30 code
: "_ \n .chain({}).map(foo).filter(bar).value();" ,
31 output
: "_ \n .chain({}).map(foo) \n .filter(bar) \n .value();" ,
33 messageId
: "expected" , data
: { callee
: ".filter" }
35 messageId
: "expected" , data
: { callee
: ".value" }
38 code
: "_ \n .chain({}) \n .map(foo) \n .filter(bar).value();" ,
39 output
: "_ \n .chain({}) \n .map(foo) \n .filter(bar) \n .value();" ,
41 messageId
: "expected" , data
: { callee
: ".value" }
44 code
: "a().b().c().e.d()" ,
45 output
: "a().b() \n .c().e.d()" ,
47 messageId
: "expected" , data
: { callee
: ".c" }
50 code
: "a.b.c().e().d()" ,
51 output
: "a.b.c().e() \n .d()" ,
53 messageId
: "expected" , data
: { callee
: ".d" }
56 code
: "_.chain({}).map(a).value(); " ,
57 output
: "_.chain({}).map(a) \n .value(); " ,
59 messageId
: "expected" , data
: { callee
: ".value" }
62 code
: "var a = m1.m2(); \n var b = m1.m2().m3().m4().m5();" ,
63 output
: "var a = m1.m2(); \n var b = m1.m2().m3() \n .m4() \n .m5();" ,
65 messageId
: "expected" , data
: { callee
: ".m4" }
67 messageId
: "expected" , data
: { callee
: ".m5" }
70 code
: "var a = m1.m2(); \n var b = m1.m2().m3() \n .m4().m5();" ,
71 output
: "var a = m1.m2(); \n var b = m1.m2().m3() \n .m4() \n .m5();" ,
73 messageId
: "expected" , data
: { callee
: ".m5" }
76 code
: "var a = m1().m2 \n .m3().m4().m5().m6().m7();" ,
77 output
: "var a = m1().m2 \n .m3().m4().m5() \n .m6() \n .m7();" ,
79 ignoreChainWithDepth
: 3
82 messageId
: "expected" , data
: { callee
: ".m6" }
84 messageId
: "expected" , data
: { callee
: ".m7" }
92 "}).on('response', function(response) {" ,
93 " // Do something with response." ,
94 " // Do something with response." ,
95 " // Do something with response." ,
96 " // Do something with response." ,
97 " // Do something with response." ,
98 " // Do something with response." ,
99 " // Do something with response." ,
100 " // Do something with response." ,
101 " // Do something with response." ,
102 " // Do something with response." ,
103 "}).on('error', function(error) {" ,
104 " // Do something with error." ,
105 " // Do something with error." ,
106 " // Do something with error." ,
107 " // Do something with error." ,
108 " // Do something with error." ,
109 " // Do something with error." ,
110 " // Do something with error." ,
111 " // Do something with error." ,
112 " // Do something with error." ,
113 " // Do something with error." ,
121 "}).on('response', function(response) {" ,
122 " // Do something with response." ,
123 " // Do something with response." ,
124 " // Do something with response." ,
125 " // Do something with response." ,
126 " // Do something with response." ,
127 " // Do something with response." ,
128 " // Do something with response." ,
129 " // Do something with response." ,
130 " // Do something with response." ,
131 " // Do something with response." ,
133 ".on('error', function(error) {" ,
134 " // Do something with error." ,
135 " // Do something with error." ,
136 " // Do something with error." ,
137 " // Do something with error." ,
138 " // Do something with error." ,
139 " // Do something with error." ,
140 " // Do something with error." ,
141 " // Do something with error." ,
142 " // Do something with error." ,
143 " // Do something with error." ,
148 messageId
: "expected" , data
: { callee
: ".on" }
150 messageId
: "expected" , data
: { callee
: ".end" }
154 "anObject.method1().method2()['method' + n]()[aCondition ?" ,
159 "anObject.method1().method2()" ,
166 messageId
: "expected" , data
: { callee
: "['method' + n]" }
168 messageId
: "expected" , data
: { callee
: "[aCondition ?" }
171 code
: "foo.bar()['foo' + \u2029 + 'bar']()" ,
172 output
: "foo.bar() \n ['foo' + \u2029 + 'bar']()" ,
173 options
: [{ ignoreChainWithDepth
: 1 }],
174 errors
: [{ messageId
: "expected" , data
: { callee
: "['foo' + " } }]
176 code
: "foo.bar()[(biz)]()" ,
177 output
: "foo.bar() \n [(biz)]()" ,
178 options
: [{ ignoreChainWithDepth
: 1 }],
179 errors
: [{ messageId
: "expected" , data
: { callee
: "[biz]" } }]
181 code
: "(foo).bar().biz()" ,
182 output
: "(foo).bar() \n .biz()" ,
183 options
: [{ ignoreChainWithDepth
: 1 }],
184 errors
: [{ messageId
: "expected" , data
: { callee
: ".biz" } }]
186 code
: "foo.bar(). /* comment */ biz()" ,
187 output
: "foo.bar() \n . /* comment */ biz()" ,
188 options
: [{ ignoreChainWithDepth
: 1 }],
189 errors
: [{ messageId
: "expected" , data
: { callee
: ".biz" } }]
191 code
: "foo.bar() /* comment */ .biz()" ,
192 output
: "foo.bar() /* comment */ \n .biz()" ,
193 options
: [{ ignoreChainWithDepth
: 1 }],
194 errors
: [{ messageId
: "expected" , data
: { callee
: ".biz" } }]