@@ -45,7 +45,14 @@ function invalid(code, output, type, line, config) {
4545 return result ;
4646}
4747
48- const ruleTester = new RuleTester ( ) ;
48+ const ruleTester = new RuleTester ( {
49+ parserOptions : {
50+ ecmaVersion : 6 ,
51+ ecmaFeatures : {
52+ jsx : true
53+ }
54+ }
55+ } ) ;
4956
5057ruleTester . run ( "no-extra-parens" , rule , {
5158 valid : [
@@ -291,7 +298,61 @@ ruleTester.run("no-extra-parens", rule, {
291298 { code : "foo instanceof (bar instanceof baz)" , options : [ "all" , { nestedBinaryExpressions : false } ] } ,
292299 { code : "foo in (bar in baz)" , options : [ "all" , { nestedBinaryExpressions : false } ] } ,
293300 { code : "foo + (bar + baz)" , options : [ "all" , { nestedBinaryExpressions : false } ] } ,
294- { code : "foo && (bar && baz)" , options : [ "all" , { nestedBinaryExpressions : false } ] }
301+ { code : "foo && (bar && baz)" , options : [ "all" , { nestedBinaryExpressions : false } ] } ,
302+
303+ // ["all", { ignoreJSX: "all" }]
304+ { code : "const Component = (<div />)" , options : [ "all" , { ignoreJSX : "all" } ] } ,
305+ { code : [
306+ "const Component = (<div>" ,
307+ " <p />" ,
308+ "</div>);"
309+ ] . join ( "\n" ) , options : [ "all" , { ignoreJSX : "all" } ] } ,
310+ { code : [
311+ "const Component = (" ,
312+ " <div />" ,
313+ ");"
314+ ] . join ( "\n" ) , options : [ "all" , { ignoreJSX : "all" } ] } ,
315+ { code : [
316+ "const Component =" ,
317+ " (<div />)"
318+ ] . join ( "\n" ) , options : [ "all" , { ignoreJSX : "all" } ] } ,
319+
320+ // ["all", { ignoreJSX: "single-line" }]
321+ { code : "const Component = (<div />);" , options : [ "all" , { ignoreJSX : "single-line" } ] } ,
322+ { code : [
323+ "const Component = (" ,
324+ " <div />" ,
325+ ");"
326+ ] . join ( "\n" ) , options : [ "all" , { ignoreJSX : "single-line" } ] } ,
327+ { code : [
328+ "const Component =" ,
329+ "(<div />)"
330+ ] . join ( "\n" ) , options : [ "all" , { ignoreJSX : "single-line" } ] } ,
331+
332+ // ["all", { ignoreJSX: "multi-line" }]
333+ { code : [
334+ "const Component = (" ,
335+ "<div>" ,
336+ " <p />" ,
337+ "</div>" ,
338+ ");"
339+ ] . join ( "\n" ) , options : [ "all" , { ignoreJSX : "multi-line" } ] } ,
340+ { code : [
341+ "const Component = (<div>" ,
342+ " <p />" ,
343+ "</div>);"
344+ ] . join ( "\n" ) , options : [ "all" , { ignoreJSX : "multi-line" } ] } ,
345+ { code : [
346+ "const Component =" ,
347+ "(<div>" ,
348+ " <p />" ,
349+ "</div>);"
350+ ] . join ( "\n" ) , options : [ "all" , { ignoreJSX : "multi-line" } ] } ,
351+ { code : [
352+ "const Component = (<div" ,
353+ " prop={true}" ,
354+ "/>)"
355+ ] . join ( "\n" ) , options : [ "all" , { ignoreJSX : "multi-line" } ] }
295356 ] ,
296357
297358 invalid : [
@@ -465,7 +526,7 @@ ruleTester.run("no-extra-parens", rule, {
465526 "function a() {" ,
466527 " return <JSX />;" ,
467528 "}"
468- ] . join ( "\n" ) , "JSXElement" , null , { parserOptions : { ecmaVersion : 6 , ecmaFeatures : { jsx : true } } } ) ,
529+ ] . join ( "\n" ) , "JSXElement" , null ) ,
469530 invalid ( [
470531 "function a() {" ,
471532 " return" ,
@@ -476,7 +537,7 @@ ruleTester.run("no-extra-parens", rule, {
476537 " return" ,
477538 " <JSX />;" ,
478539 "}"
479- ] . join ( "\n" ) , "JSXElement" , null , { parserOptions : { ecmaVersion : 6 , ecmaFeatures : { jsx : true } } } ) ,
540+ ] . join ( "\n" ) , "JSXElement" , null ) ,
480541 invalid ( [
481542 "function a() {" ,
482543 " return ((" ,
@@ -489,7 +550,7 @@ ruleTester.run("no-extra-parens", rule, {
489550 " <JSX />" ,
490551 " );" ,
491552 "}"
492- ] . join ( "\n" ) , "JSXElement" , null , { parserOptions : { ecmaVersion : 6 , ecmaFeatures : { jsx : true } } } ) ,
553+ ] . join ( "\n" ) , "JSXElement" , null ) ,
493554 invalid ( "throw (a);" , "throw a;" , "Identifier" ) ,
494555 invalid ( [
495556 "throw ((" ,
@@ -706,6 +767,55 @@ ruleTester.run("no-extra-parens", rule, {
706767 invalid ( "foo instanceof (bar)" , "foo instanceof bar" , "Identifier" , 1 , { options : [ "all" , { nestedBinaryExpressions : false } ] } ) ,
707768 invalid ( "foo in (bar)" , "foo in bar" , "Identifier" , 1 , { options : [ "all" , { nestedBinaryExpressions : false } ] } ) ,
708769 invalid ( "foo + (bar)" , "foo + bar" , "Identifier" , 1 , { options : [ "all" , { nestedBinaryExpressions : false } ] } ) ,
709- invalid ( "foo && (bar)" , "foo && bar" , "Identifier" , 1 , { options : [ "all" , { nestedBinaryExpressions : false } ] } )
770+ invalid ( "foo && (bar)" , "foo && bar" , "Identifier" , 1 , { options : [ "all" , { nestedBinaryExpressions : false } ] } ) ,
771+
772+ // ["all", { ignoreJSX: "multi-line" }]
773+ invalid ( "const Component = (<div />);" , "const Component = <div />;" , "JSXElement" , 1 , {
774+ options : [ "all" , { ignoreJSX : "multi-line" } ]
775+ } ) ,
776+ invalid ( [
777+ "const Component = (" ,
778+ " <div />" ,
779+ ");"
780+ ] . join ( "\n" ) , "const Component = \n <div />\n;" , "JSXElement" , 1 , {
781+ options : [ "all" , { ignoreJSX : "multi-line" } ]
782+ } ) ,
783+
784+ // ["all", { ignoreJSX: "single-line" }]
785+ invalid ( [
786+ "const Component = (" ,
787+ "<div>" ,
788+ " <p />" ,
789+ "</div>" ,
790+ ");"
791+ ] . join ( "\n" ) , "const Component = \n<div>\n <p />\n</div>\n;" , "JSXElement" , 1 , {
792+ options : [ "all" , { ignoreJSX : "single-line" } ]
793+ } ) ,
794+ invalid ( [
795+ "const Component = (<div>" ,
796+ " <p />" ,
797+ "</div>);"
798+ ] . join ( "\n" ) , "const Component = <div>\n <p />\n</div>;" , "JSXElement" , 1 , {
799+ options : [ "all" , { ignoreJSX : "single-line" } ]
800+ } ) ,
801+ invalid ( [
802+ "const Component = (<div" ,
803+ " prop={true}" ,
804+ "/>)"
805+ ] . join ( "\n" ) , "const Component = <div\n prop={true}\n/>" , "JSXElement" , 1 , {
806+ options : [ "all" , { ignoreJSX : "single-line" } ]
807+ } ) ,
808+
809+ // ["all", { ignoreJSX: "none" }] default, same as unspecified
810+ invalid ( "const Component = (<div />);" , "const Component = <div />;" , "JSXElement" , 1 , {
811+ options : [ "all" , { ignoreJSX : "none" } ]
812+ } ) ,
813+ invalid ( [
814+ "const Component = (<div>" ,
815+ "<p />" ,
816+ "</div>)"
817+ ] . join ( "\n" ) , "const Component = <div>\n<p />\n</div>" , "JSXElement" , 1 , {
818+ options : [ "all" , { ignoreJSX : "none" } ]
819+ } )
710820 ]
711821} ) ;
0 commit comments