@@ -318,6 +318,17 @@ ruleTester.run("complexity", rule, {
318318 options : [ 0 ] ,
319319 errors : [ makeError ( "Function 'a'" , 1 , 0 ) ] ,
320320 } ,
321+ {
322+ code : "function foo(x) {if (x > 10) {return 'x is greater than 10';} else if (x > 5) {return 'x is greater than 5';} else {return 'x is less than 5';}}" ,
323+ options : [ 2 ] ,
324+ errors : [
325+ {
326+ ...makeError ( "Function 'foo'" , 3 , 2 ) ,
327+ column : 1 ,
328+ endColumn : 13 ,
329+ } ,
330+ ] ,
331+ } ,
321332 {
322333 code : "var func = function () {}" ,
323334 options : [ 0 ] ,
@@ -827,13 +838,38 @@ ruleTester.run("complexity", rule, {
827838 } ,
828839 ] ,
829840 } ,
841+ {
842+ code : "class C { x = () => a || b || c; y = f || g || h; }" ,
843+ options : [ 2 ] ,
844+ languageOptions : { ecmaVersion : 2022 } ,
845+ errors : [
846+ {
847+ ...makeError ( "Method 'x'" , 3 , 2 ) ,
848+ column : 11 ,
849+ endColumn : 15 ,
850+ } ,
851+ {
852+ ...makeError ( "Class field initializer" , 3 , 2 ) ,
853+ column : 38 ,
854+ endColumn : 49 ,
855+ } ,
856+ ] ,
857+ } ,
830858
831859 // object property options
832860 {
833861 code : "function a(x) {}" ,
834862 options : [ { max : 0 } ] ,
835863 errors : [ makeError ( "Function 'a'" , 1 , 0 ) ] ,
836864 } ,
865+ {
866+ code : "const obj = { b: (a) => a?.b?.c, c: function (a) { return a?.b?.c; } };" ,
867+ options : [ { max : 2 } ] ,
868+ errors : [
869+ { ...makeError ( "Method 'b'" , 3 , 2 ) , column : 15 , endColumn : 18 } ,
870+ { ...makeError ( "Method 'c'" , 3 , 2 ) , column : 34 , endColumn : 46 } ,
871+ ] ,
872+ } ,
837873
838874 // optional chaining
839875 {
@@ -869,7 +905,13 @@ ruleTester.run("complexity", rule, {
869905 {
870906 code : "function a(b) { b?.c.d?.e; }" ,
871907 options : [ { max : 2 } ] ,
872- errors : [ makeError ( "Function 'a'" , 3 , 2 ) ] ,
908+ errors : [
909+ {
910+ ...makeError ( "Function 'a'" , 3 , 2 ) ,
911+ column : 1 ,
912+ endColumn : 11 ,
913+ } ,
914+ ] ,
873915 } ,
874916 {
875917 code : "function a(b) { b?.c?.(); }" ,
0 commit comments