@@ -4,7 +4,7 @@ const rule = require('../rules/always-return')
44const RuleTester = require ( 'eslint' ) . RuleTester
55const ruleTester = new RuleTester ( {
66 parserOptions : {
7- ecmaVersion : 6 ,
7+ ecmaVersion : 11 ,
88 } ,
99} )
1010
@@ -48,6 +48,59 @@ ruleTester.run('always-return', rule, {
4848 }
4949 return x
5050 })` ,
51+ {
52+ code : 'hey.then(x => { console.log(x) })' ,
53+ options : [ { ignoreLastCallback : true } ] ,
54+ } ,
55+ {
56+ code : 'if(foo) { hey.then(x => { console.log(x) }) }' ,
57+ options : [ { ignoreLastCallback : true } ] ,
58+ } ,
59+ {
60+ code : 'void hey.then(x => { console.log(x) })' ,
61+ options : [ { ignoreLastCallback : true } ] ,
62+ } ,
63+ {
64+ code : `
65+ async function foo() {
66+ await hey.then(x => { console.log(x) })
67+ }` ,
68+ options : [ { ignoreLastCallback : true } ] ,
69+ } ,
70+ {
71+ code : `hey?.then(x => { console.log(x) })` ,
72+ options : [ { ignoreLastCallback : true } ] ,
73+ } ,
74+ {
75+ code : `foo = (hey.then(x => { console.log(x) }), 42)` ,
76+ options : [ { ignoreLastCallback : true } ] ,
77+ } ,
78+ {
79+ code : `(42, hey.then(x => { console.log(x) }))` ,
80+ options : [ { ignoreLastCallback : true } ] ,
81+ } ,
82+ {
83+ code : `
84+ hey
85+ .then(x => { console.log(x) })
86+ .catch(e => console.error(e))` ,
87+ options : [ { ignoreLastCallback : true } ] ,
88+ } ,
89+ {
90+ code : `
91+ hey
92+ .then(x => { console.log(x) })
93+ .catch(e => console.error(e))
94+ .finally(() => console.error('end'))` ,
95+ options : [ { ignoreLastCallback : true } ] ,
96+ } ,
97+ {
98+ code : `
99+ hey
100+ .then(x => { console.log(x) })
101+ .finally(() => console.error('end'))` ,
102+ options : [ { ignoreLastCallback : true } ] ,
103+ } ,
51104 ] ,
52105
53106 invalid : [
@@ -130,5 +183,44 @@ ruleTester.run('always-return', rule, {
130183 })` ,
131184 errors : [ { message } ] ,
132185 } ,
186+ {
187+ code : `
188+ hey
189+ .then(function(x) { console.log(x) /* missing return here */ })
190+ .then(function(y) { console.log(y) /* no error here */ })` ,
191+ options : [ { ignoreLastCallback : true } ] ,
192+ errors : [ { message, line : 3 } ] ,
193+ } ,
194+ {
195+ code : `const foo = hey.then(function(x) {});` ,
196+ options : [ { ignoreLastCallback : true } ] ,
197+ errors : [ { message } ] ,
198+ } ,
199+ {
200+ code : `
201+ function foo() {
202+ return hey.then(function(x) {});
203+ }` ,
204+ options : [ { ignoreLastCallback : true } ] ,
205+ errors : [ { message } ] ,
206+ } ,
207+ {
208+ code : `
209+ async function foo() {
210+ return await hey.then(x => { console.log(x) })
211+ }` ,
212+ options : [ { ignoreLastCallback : true } ] ,
213+ errors : [ { message } ] ,
214+ } ,
215+ {
216+ code : `const foo = hey?.then(x => { console.log(x) })` ,
217+ options : [ { ignoreLastCallback : true } ] ,
218+ errors : [ { message } ] ,
219+ } ,
220+ {
221+ code : `const foo = (42, hey.then(x => { console.log(x) }))` ,
222+ options : [ { ignoreLastCallback : true } ] ,
223+ errors : [ { message } ] ,
224+ } ,
133225 ] ,
134226} )
0 commit comments