55const rule = require ( '../../../lib/rules/template-no-unnecessary-curly-parens' ) ;
66const RuleTester = require ( 'eslint' ) . RuleTester ;
77
8- const ruleTester = new RuleTester ( {
8+ const validHbs = [
9+ '{{foo}}' ,
10+ '{{this.foo}}' ,
11+ '{{(helper)}}' ,
12+ '{{(this.helper)}}' ,
13+ '{{concat "a" "b"}}' ,
14+ '{{concat (capitalize "foo") "-bar"}}' ,
15+ ] ;
16+
17+ const invalidHbs = [
18+ {
19+ code : '<FooBar @x="{{index}}X{{(someHelper foo)}}" />' ,
20+ output : '<FooBar @x="{{index}}X{{someHelper foo}}" />' ,
21+ errors : [ { messageId : 'noUnnecessaryCurlyParens' } ] ,
22+ } ,
23+ {
24+ code : '<FooBar @x="{{index}}XY{{(someHelper foo)}}" />' ,
25+ output : '<FooBar @x="{{index}}XY{{someHelper foo}}" />' ,
26+ errors : [ { messageId : 'noUnnecessaryCurlyParens' } ] ,
27+ } ,
28+ {
29+ code : '<FooBar @x="{{index}}--{{(someHelper foo)}}" />' ,
30+ output : '<FooBar @x="{{index}}--{{someHelper foo}}" />' ,
31+ errors : [ { messageId : 'noUnnecessaryCurlyParens' } ] ,
32+ } ,
33+ {
34+ code : '{{(concat "a" "b")}}' ,
35+ output : '{{concat "a" "b"}}' ,
36+ errors : [ { messageId : 'noUnnecessaryCurlyParens' } ] ,
37+ } ,
38+ {
39+ code : '{{(helper a="b")}}' ,
40+ output : '{{helper a="b"}}' ,
41+ errors : [ { messageId : 'noUnnecessaryCurlyParens' } ] ,
42+ } ,
43+ ] ;
44+
45+ function wrapTemplate ( entry ) {
46+ if ( typeof entry === 'string' ) {
47+ return `<template>${ entry } </template>` ;
48+ }
49+
50+ return {
51+ ...entry ,
52+ code : `<template>${ entry . code } </template>` ,
53+ output : entry . output ? `<template>${ entry . output } </template>` : entry . output ,
54+ } ;
55+ }
56+
57+ const gjsRuleTester = new RuleTester ( {
958 parser : require . resolve ( 'ember-eslint-parser' ) ,
1059 parserOptions : { ecmaVersion : 2022 , sourceType : 'module' } ,
1160} ) ;
1261
13- ruleTester . run ( 'template-no-unnecessary-curly-parens' , rule , {
14- valid : [
15- '<template>{{helper param}}</template>' ,
16- '<template>{{#if condition}}text{{/if}}</template>' ,
17- '<template>{{this.property}}</template>' ,
18-
19- '<template>{{foo}}</template>' ,
20- '<template>{{this.foo}}</template>' ,
21- '<template>{{(helper)}}</template>' ,
22- '<template>{{(this.helper)}}</template>' ,
23- '<template>{{concat "a" "b"}}</template>' ,
24- '<template>{{concat (capitalize "foo") "-bar"}}</template>' ,
25- ] ,
26- invalid : [
27- {
28- code : '<template>{{(helper value)}}</template>' ,
29- output : '<template>{{helper value}}</template>' ,
30- errors : [ { messageId : 'noUnnecessaryCurlyParens' } ] ,
31- } ,
32- {
33- code : '<template>{{(concat "a" "b")}}</template>' ,
34- output : '<template>{{concat "a" "b"}}</template>' ,
35- errors : [ { messageId : 'noUnnecessaryCurlyParens' } ] ,
36- } ,
37- {
38- code : '<template>{{(if condition "yes" "no")}}</template>' ,
39- output : '<template>{{if condition "yes" "no"}}</template>' ,
40- errors : [ { messageId : 'noUnnecessaryCurlyParens' } ] ,
41- } ,
42-
43- {
44- code : '<template><FooBar @x="{{index}}X{{(someHelper foo)}}" /></template>' ,
45- output : '<template><FooBar @x="{{index}}X{{someHelper foo}}" /></template>' ,
46- errors : [ { messageId : 'noUnnecessaryCurlyParens' } ] ,
47- } ,
48- {
49- code : '<template><FooBar @x="{{index}}XY{{(someHelper foo)}}" /></template>' ,
50- output : '<template><FooBar @x="{{index}}XY{{someHelper foo}}" /></template>' ,
51- errors : [ { messageId : 'noUnnecessaryCurlyParens' } ] ,
52- } ,
53- {
54- code : '<template><FooBar @x="{{index}}--{{(someHelper foo)}}" /></template>' ,
55- output : '<template><FooBar @x="{{index}}--{{someHelper foo}}" /></template>' ,
56- errors : [ { messageId : 'noUnnecessaryCurlyParens' } ] ,
57- } ,
58- {
59- code : '<template>{{(helper a="b")}}</template>' ,
60- output : '<template>{{helper a="b"}}</template>' ,
61- errors : [ { messageId : 'noUnnecessaryCurlyParens' } ] ,
62- } ,
63- ] ,
62+ gjsRuleTester . run ( 'template-no-unnecessary-curly-parens' , rule , {
63+ valid : validHbs . map ( wrapTemplate ) ,
64+ invalid : invalidHbs . map ( wrapTemplate ) ,
6465} ) ;
6566
6667const hbsRuleTester = new RuleTester ( {
@@ -72,39 +73,6 @@ const hbsRuleTester = new RuleTester({
7273} ) ;
7374
7475hbsRuleTester . run ( 'template-no-unnecessary-curly-parens' , rule , {
75- valid : [
76- '{{foo}}' ,
77- '{{this.foo}}' ,
78- '{{(helper)}}' ,
79- '{{(this.helper)}}' ,
80- '{{concat "a" "b"}}' ,
81- '{{concat (capitalize "foo") "-bar"}}' ,
82- ] ,
83- invalid : [
84- {
85- code : '<FooBar @x="{{index}}X{{(someHelper foo)}}" />' ,
86- output : '<FooBar @x="{{index}}X{{someHelper foo}}" />' ,
87- errors : [ { message : 'Unnecessary parentheses enclosing statement.' } ] ,
88- } ,
89- {
90- code : '<FooBar @x="{{index}}XY{{(someHelper foo)}}" />' ,
91- output : '<FooBar @x="{{index}}XY{{someHelper foo}}" />' ,
92- errors : [ { message : 'Unnecessary parentheses enclosing statement.' } ] ,
93- } ,
94- {
95- code : '<FooBar @x="{{index}}--{{(someHelper foo)}}" />' ,
96- output : '<FooBar @x="{{index}}--{{someHelper foo}}" />' ,
97- errors : [ { message : 'Unnecessary parentheses enclosing statement.' } ] ,
98- } ,
99- {
100- code : '{{(concat "a" "b")}}' ,
101- output : '{{concat "a" "b"}}' ,
102- errors : [ { message : 'Unnecessary parentheses enclosing statement.' } ] ,
103- } ,
104- {
105- code : '{{(helper a="b")}}' ,
106- output : '{{helper a="b"}}' ,
107- errors : [ { message : 'Unnecessary parentheses enclosing statement.' } ] ,
108- } ,
109- ] ,
76+ valid : validHbs ,
77+ invalid : invalidHbs ,
11078} ) ;
0 commit comments