@@ -79,6 +79,7 @@ ruleTester.run("yoda", rule, {
7979
8080 {
8181 code : "if (\"red\" == value) {}" ,
82+ output : "if (value == \"red\") {}" ,
8283 options : [ "never" ] ,
8384 errors : [
8485 {
@@ -89,6 +90,7 @@ ruleTester.run("yoda", rule, {
8990 } ,
9091 {
9192 code : "if (true === value) {}" ,
93+ output : "if (value === true) {}" ,
9294 options : [ "never" ] ,
9395 errors : [
9496 {
@@ -99,6 +101,7 @@ ruleTester.run("yoda", rule, {
99101 } ,
100102 {
101103 code : "if (5 != value) {}" ,
104+ output : "if (value != 5) {}" ,
102105 options : [ "never" ] ,
103106 errors : [
104107 {
@@ -109,6 +112,7 @@ ruleTester.run("yoda", rule, {
109112 } ,
110113 {
111114 code : "if (null !== value) {}" ,
115+ output : "if (value !== null) {}" ,
112116 options : [ "never" ] ,
113117 errors : [
114118 {
@@ -119,6 +123,7 @@ ruleTester.run("yoda", rule, {
119123 } ,
120124 {
121125 code : "if (\"red\" <= value) {}" ,
126+ output : "if (value >= \"red\") {}" ,
122127 options : [ "never" ] ,
123128 errors : [
124129 {
@@ -129,6 +134,7 @@ ruleTester.run("yoda", rule, {
129134 } ,
130135 {
131136 code : "if (true >= value) {}" ,
137+ output : "if (value <= true) {}" ,
132138 options : [ "never" ] ,
133139 errors : [
134140 {
@@ -139,6 +145,7 @@ ruleTester.run("yoda", rule, {
139145 } ,
140146 {
141147 code : "var foo = (5 < value) ? true : false" ,
148+ output : "var foo = (value > 5) ? true : false" ,
142149 options : [ "never" ] ,
143150 errors : [
144151 {
@@ -149,6 +156,7 @@ ruleTester.run("yoda", rule, {
149156 } ,
150157 {
151158 code : "function foo() { return (null > value); }" ,
159+ output : "function foo() { return (value < null); }" ,
152160 options : [ "never" ] ,
153161 errors : [
154162 {
@@ -159,6 +167,7 @@ ruleTester.run("yoda", rule, {
159167 } ,
160168 {
161169 code : "if (-1 < str.indexOf(substr)) {}" ,
170+ output : "if (str.indexOf(substr) > -1) {}" ,
162171 options : [ "never" ] ,
163172 errors : [
164173 {
@@ -169,6 +178,7 @@ ruleTester.run("yoda", rule, {
169178 } ,
170179 {
171180 code : "if (value == \"red\") {}" ,
181+ output : "if (\"red\" == value) {}" ,
172182 options : [ "always" ] ,
173183 errors : [
174184 {
@@ -179,6 +189,7 @@ ruleTester.run("yoda", rule, {
179189 } ,
180190 {
181191 code : "if (value === true) {}" ,
192+ output : "if (true === value) {}" ,
182193 options : [ "always" ] ,
183194 errors : [
184195 {
@@ -189,6 +200,7 @@ ruleTester.run("yoda", rule, {
189200 } ,
190201 {
191202 code : "if (a < 0 && 0 <= b && b < 1) {}" ,
203+ output : "if (a < 0 && b >= 0 && b < 1) {}" ,
192204 options : [ "never" , { exceptRange : true } ] ,
193205 errors : [
194206 {
@@ -199,6 +211,7 @@ ruleTester.run("yoda", rule, {
199211 } ,
200212 {
201213 code : "if (0 <= a && a < 1 && b < 1) {}" ,
214+ output : "if (a >= 0 && a < 1 && b < 1) {}" ,
202215 options : [ "never" , { exceptRange : true } ] ,
203216 errors : [
204217 {
@@ -209,6 +222,7 @@ ruleTester.run("yoda", rule, {
209222 } ,
210223 {
211224 code : "if (1 < a && a < 0) {}" ,
225+ output : "if (a > 1 && a < 0) {}" ,
212226 options : [ "never" , { exceptRange : true } ] ,
213227 errors : [
214228 {
@@ -219,6 +233,7 @@ ruleTester.run("yoda", rule, {
219233 } ,
220234 {
221235 code : "0 < a && a < 1" ,
236+ output : "a > 0 && a < 1" ,
222237 options : [ "never" , { exceptRange : true } ] ,
223238 errors : [
224239 {
@@ -229,6 +244,7 @@ ruleTester.run("yoda", rule, {
229244 } ,
230245 {
231246 code : "var a = b < 0 || 1 <= b;" ,
247+ output : "var a = b < 0 || b >= 1;" ,
232248 options : [ "never" , { exceptRange : true } ] ,
233249 errors : [
234250 {
@@ -239,6 +255,7 @@ ruleTester.run("yoda", rule, {
239255 } ,
240256 {
241257 code : "if (0 <= x && x < -1) {}" ,
258+ output : "if (x >= 0 && x < -1) {}" ,
242259 options : [ "never" , { exceptRange : true } ] ,
243260 errors : [
244261 {
@@ -249,6 +266,7 @@ ruleTester.run("yoda", rule, {
249266 } ,
250267 {
251268 code : "var a = (b < 0 && 0 <= b);" ,
269+ output : "var a = (0 > b && 0 <= b);" ,
252270 options : [ "always" , { exceptRange : true } ] ,
253271 errors : [
254272 {
@@ -259,6 +277,7 @@ ruleTester.run("yoda", rule, {
259277 } ,
260278 {
261279 code : "if (0 <= a[b] && a['b'] < 1) {}" ,
280+ output : "if (a[b] >= 0 && a['b'] < 1) {}" ,
262281 options : [ "never" , { exceptRange : true } ] ,
263282 errors : [
264283 {
@@ -269,6 +288,7 @@ ruleTester.run("yoda", rule, {
269288 } ,
270289 {
271290 code : "if (0 <= a[b()] && a[b()] < 1) {}" ,
291+ output : "if (a[b()] >= 0 && a[b()] < 1) {}" ,
272292 options : [ "never" , { exceptRange : true } ] ,
273293 errors : [
274294 {
@@ -279,6 +299,7 @@ ruleTester.run("yoda", rule, {
279299 } ,
280300 {
281301 code : "if (3 == a) {}" ,
302+ output : "if (a == 3) {}" ,
282303 options : [ "never" , { onlyEquality : true } ] ,
283304 errors : [
284305 {
@@ -289,6 +310,7 @@ ruleTester.run("yoda", rule, {
289310 } ,
290311 {
291312 code : "foo(3 === a);" ,
313+ output : "foo(a === 3);" ,
292314 options : [ "never" , { onlyEquality : true } ] ,
293315 errors : [
294316 {
@@ -299,6 +321,7 @@ ruleTester.run("yoda", rule, {
299321 } ,
300322 {
301323 code : "foo(a === 3);" ,
324+ output : "foo(3 === a);" ,
302325 options : [ "always" , { onlyEquality : true } ] ,
303326 errors : [
304327 {
@@ -309,13 +332,57 @@ ruleTester.run("yoda", rule, {
309332 } ,
310333 {
311334 code : "if (0 <= x && x < 1) {}" ,
335+ output : "if (x >= 0 && x < 1) {}" ,
312336 errors : [
313337 {
314338 message : "Expected literal to be on the right side of <=." ,
315339 type : "BinaryExpression"
316340 }
317341 ]
342+ } ,
343+ {
344+ code : "if ( /* a */ 0 /* b */ < /* c */ foo /* d */ ) {}" ,
345+ output : "if ( /* a */ foo /* b */ > /* c */ 0 /* d */ ) {}" ,
346+ options : [ "never" ] ,
347+ errors : [
348+ {
349+ message : "Expected literal to be on the right side of <." ,
350+ type : "BinaryExpression"
351+ }
352+ ]
353+ } ,
354+ {
355+ code : "if ( /* a */ foo /* b */ > /* c */ 0 /* d */ ) {}" ,
356+ output : "if ( /* a */ 0 /* b */ < /* c */ foo /* d */ ) {}" ,
357+ options : [ "always" ] ,
358+ errors : [
359+ {
360+ message : "Expected literal to be on the left side of >." ,
361+ type : "BinaryExpression"
362+ }
363+ ]
364+ } ,
365+ {
366+ code : "if (foo()===1) {}" ,
367+ output : "if (1===foo()) {}" ,
368+ options : [ "always" ] ,
369+ errors : [
370+ {
371+ message : "Expected literal to be on the left side of ===." ,
372+ type : "BinaryExpression"
373+ }
374+ ]
375+ } ,
376+ {
377+ code : "if (foo() === 1) {}" ,
378+ output : "if (1 === foo()) {}" ,
379+ options : [ "always" ] ,
380+ errors : [
381+ {
382+ message : "Expected literal to be on the left side of ===." ,
383+ type : "BinaryExpression"
384+ }
385+ ]
318386 }
319-
320387 ]
321388} ) ;
0 commit comments