@@ -29,6 +29,12 @@ const valid = [
2929 "(a) => {\n}" ,
3030 "a.then((foo) => {});" ,
3131 "a.then((foo) => { if (true) {}; });" ,
32+ "const f = (/* */a) => a + a;" ,
33+ "const f = (a/** */) => a + a;" ,
34+ "const f = (a//\n) => a + a;" ,
35+ "const f = (//\na) => a + a;" ,
36+ "const f = (/*\n */a//\n) => a + a;" ,
37+ "const f = (/** @type {number} */a/**hello*/) => a + a;" ,
3238 { code : "a.then(async (foo) => { if (true) {}; });" , parserOptions : { ecmaVersion : 8 } } ,
3339
3440 // "always" (explicit)
@@ -68,7 +74,69 @@ const valid = [
6874 { code : "async a => ({})" , options : [ "as-needed" , { requireForBlockBody : true } ] , parserOptions : { ecmaVersion : 8 } } ,
6975 { code : "async a => a" , options : [ "as-needed" , { requireForBlockBody : true } ] , parserOptions : { ecmaVersion : 8 } } ,
7076 { code : "(a: T) => a" , options : [ "as-needed" , { requireForBlockBody : true } ] , parser : parser ( "identifer-type" ) } ,
71- { code : "(a): T => a" , options : [ "as-needed" , { requireForBlockBody : true } ] , parser : parser ( "return-type" ) }
77+ { code : "(a): T => a" , options : [ "as-needed" , { requireForBlockBody : true } ] , parser : parser ( "return-type" ) } ,
78+ {
79+ code : "const f = (/** @type {number} */a/**hello*/) => a + a;" ,
80+ options : [ "as-needed" ]
81+ } ,
82+ {
83+ code : "const f = (/* */a) => a + a;" ,
84+ options : [ "as-needed" ]
85+ } ,
86+ {
87+ code : "const f = (a/** */) => a + a;" ,
88+ options : [ "as-needed" ]
89+ } ,
90+ {
91+ code : "const f = (a//\n) => a + a;" ,
92+ options : [ "as-needed" ]
93+ } ,
94+ {
95+ code : "const f = (//\na) => a + a;" ,
96+ options : [ "as-needed" ]
97+ } ,
98+ {
99+ code : "const f = (/*\n */a//\n) => a + a;" ,
100+ options : [ "as-needed" ]
101+ } ,
102+ {
103+ code : "var foo = (a,/**/) => b;" ,
104+ parserOptions : { ecmaVersion : 2017 } ,
105+ options : [ "as-needed" ]
106+ } ,
107+ {
108+ code : "var foo = (a , /**/) => b;" ,
109+ parserOptions : { ecmaVersion : 2017 } ,
110+ options : [ "as-needed" ]
111+ } ,
112+ {
113+ code : "var foo = (a\n,\n/**/) => b;" ,
114+ parserOptions : { ecmaVersion : 2017 } ,
115+ options : [ "as-needed" ]
116+ } ,
117+ {
118+ code : "var foo = (a,//\n) => b;" ,
119+ parserOptions : { ecmaVersion : 2017 } ,
120+ options : [ "as-needed" ]
121+ } ,
122+ {
123+ code : "const i = (a/**/,) => a + a;" ,
124+ parserOptions : { ecmaVersion : 2017 } ,
125+ options : [ "as-needed" ]
126+ } ,
127+ {
128+ code : "const i = (a \n /**/,) => a + a;" ,
129+ parserOptions : { ecmaVersion : 2017 } ,
130+ options : [ "as-needed" ]
131+ } ,
132+ {
133+ code : "var bar = ({/*comment here*/a}) => a" ,
134+ options : [ "as-needed" ]
135+ } ,
136+ {
137+ code : "var bar = (/*comment here*/{a}) => a" ,
138+ options : [ "as-needed" ]
139+ }
72140] ;
73141
74142const type = "ArrowFunctionExpression" ;
@@ -271,7 +339,78 @@ const invalid = [
271339 messageId : "unexpectedParensInline" ,
272340 type
273341 } ]
342+ } ,
343+ {
344+ code : "const f = /** @type {number} */(a)/**hello*/ => a + a;" ,
345+ options : [ "as-needed" ] ,
346+ output : "const f = /** @type {number} */a/**hello*/ => a + a;" ,
347+ errors : [ {
348+ line : 1 ,
349+ column : 33 ,
350+ type,
351+ messageId : "unexpectedParens" ,
352+ endLine : 1 ,
353+ endColumn : 34
354+ } ]
355+ } ,
356+ {
357+ code : "const f = //\n(a) => a + a;" ,
358+ output : "const f = //\na => a + a;" ,
359+ options : [ "as-needed" ] ,
360+ errors : [ {
361+ line : 2 ,
362+ column : 2 ,
363+ type,
364+ messageId : "unexpectedParens" ,
365+ endLine : 2 ,
366+ endColumn : 3
367+ } ]
368+ } ,
369+ {
370+ code : "var foo = /**/ a => b;" ,
371+ output : "var foo = /**/ (a) => b;" ,
372+ errors : [ {
373+ line : 1 ,
374+ column : 16 ,
375+ type : "ArrowFunctionExpression" ,
376+ messageId : "expectedParens" ,
377+ endLine : 1 ,
378+ endColumn : 17
379+ } ]
380+ } ,
381+ {
382+ code : "var bar = a /**/ => b;" ,
383+ output : "var bar = (a) /**/ => b;" ,
384+ errors : [ {
385+ line : 1 ,
386+ column : 11 ,
387+ type : "ArrowFunctionExpression" ,
388+ messageId : "expectedParens" ,
389+ endLine : 1 ,
390+ endColumn : 12
391+ } ]
392+ } ,
393+ {
394+ code : `const foo = a => {};
395+
396+ // comment between 'a' and an unrelated closing paren
397+
398+ bar();` ,
399+ output : `const foo = (a) => {};
400+
401+ // comment between 'a' and an unrelated closing paren
402+
403+ bar();` ,
404+ errors : [ {
405+ line : 1 ,
406+ column : 13 ,
407+ type : "ArrowFunctionExpression" ,
408+ messageId : "expectedParens" ,
409+ endLine : 1 ,
410+ endColumn : 14
411+ } ]
274412 }
413+
275414] ;
276415
277416ruleTester . run ( "arrow-parens" , rule , {
0 commit comments