11const rule = require ( '../../../lib/rules/template-no-unnecessary-curly-strings' ) ;
22const RuleTester = require ( 'eslint' ) . RuleTester ;
33
4- const ruleTester = new RuleTester ( {
4+ const validHbs = [
5+ '<FooBar class="btn" />' ,
6+ '{{foo}}' ,
7+ '{{(foo)}}' ,
8+ '{{this.calculate 1 2 op="add"}}' ,
9+ '{{get address part}}' ,
10+ 'foo' ,
11+ '"foo"' ,
12+ '<FooBar value=12345 />' ,
13+ '<FooBar value=null />' ,
14+ '<FooBar value=true />' ,
15+ '<FooBar value=undefined />' ,
16+ '<FooBar value={{12345}} />' ,
17+ '<FooBar value={{null}} />' ,
18+ '<FooBar value={{true}} />' ,
19+ '<FooBar value={{undefined}} />' ,
20+ ] ;
21+
22+ const invalidHbs = [
23+ {
24+ code : '<FooBar class={{"btn"}} @fooArg={{\'barbaz\'}} />' ,
25+ output : '<FooBar class="btn" @fooArg=\'barbaz\' />' ,
26+ errors : [ { messageId : 'unnecessary' } , { messageId : 'unnecessary' } ] ,
27+ } ,
28+ {
29+ code : '<FooBar class="btn">{{"Foo"}}</FooBar>' ,
30+ output : '<FooBar class="btn">Foo</FooBar>' ,
31+ errors : [ { messageId : 'unnecessary' } ] ,
32+ } ,
33+ ] ;
34+
35+ function wrapTemplate ( entry ) {
36+ if ( typeof entry === 'string' ) {
37+ return `<template>${ entry } </template>` ;
38+ }
39+
40+ return {
41+ ...entry ,
42+ code : `<template>${ entry . code } </template>` ,
43+ output : entry . output ? `<template>${ entry . output } </template>` : entry . output ,
44+ } ;
45+ }
46+
47+ const gjsRuleTester = new RuleTester ( {
548 parser : require . resolve ( 'ember-eslint-parser' ) ,
649 parserOptions : { ecmaVersion : 2022 , sourceType : 'module' } ,
750} ) ;
8- ruleTester . run ( 'template-no-unnecessary-curly-strings' , rule , {
9- valid : [
10- '<template><div class="foo"></div></template>' ,
11- '<template><FooBar class="btn" /></template>' ,
12- '<template>{{foo}}</template>' ,
13- '<template>{{(foo)}}</template>' ,
14- '<template>{{this.calculate 1 2 op="add"}}</template>' ,
15- '<template>{{get address part}}</template>' ,
16- '<template>foo</template>' ,
17- '<template>"foo"</template>' ,
18- '<template><FooBar value=12345 /></template>' ,
19- '<template><FooBar value=null /></template>' ,
20- '<template><FooBar value=true /></template>' ,
21- '<template><FooBar value=undefined /></template>' ,
22- '<template><FooBar value={{12345}} /></template>' ,
23- '<template><FooBar value={{null}} /></template>' ,
24- '<template><FooBar value={{true}} /></template>' ,
25- '<template><FooBar value={{undefined}} /></template>' ,
26- ] ,
27- invalid : [
28- {
29- code : '<template><div class={{"foo"}}></div></template>' ,
30- output : '<template><div class="foo"></div></template>' ,
31- errors : [ { messageId : 'unnecessary' } ] ,
32- } ,
3351
34- {
35- code : '<template><FooBar class={{"btn"}} @fooArg={{\'barbaz\'}} /></template>' ,
36- output : '<template><FooBar class="btn" @fooArg=\'barbaz\' /></template>' ,
37- errors : [ { messageId : 'unnecessary' } , { messageId : 'unnecessary' } ] ,
38- } ,
39- {
40- code : '<template><FooBar class="btn">{{"Foo"}}</FooBar></template>' ,
41- output : '<template><FooBar class="btn">Foo</FooBar></template>' ,
42- errors : [ { messageId : 'unnecessary' } ] ,
43- } ,
44- ] ,
52+ gjsRuleTester . run ( 'template-no-unnecessary-curly-strings' , rule , {
53+ valid : validHbs . map ( wrapTemplate ) ,
54+ invalid : invalidHbs . map ( wrapTemplate ) ,
4555} ) ;
4656
4757const hbsRuleTester = new RuleTester ( {
@@ -53,36 +63,6 @@ const hbsRuleTester = new RuleTester({
5363} ) ;
5464
5565hbsRuleTester . run ( 'template-no-unnecessary-curly-strings' , rule , {
56- valid : [
57- '<FooBar class="btn" />' ,
58- '{{foo}}' ,
59- '{{(foo)}}' ,
60- '{{this.calculate 1 2 op="add"}}' ,
61- '{{get address part}}' ,
62- 'foo' ,
63- '"foo"' ,
64- '<FooBar value=12345 />' ,
65- '<FooBar value=null />' ,
66- '<FooBar value=true />' ,
67- '<FooBar value=undefined />' ,
68- '<FooBar value={{12345}} />' ,
69- '<FooBar value={{null}} />' ,
70- '<FooBar value={{true}} />' ,
71- '<FooBar value={{undefined}} />' ,
72- ] ,
73- invalid : [
74- {
75- code : '<FooBar class={{"btn"}} @fooArg={{\'barbaz\'}} />' ,
76- output : '<FooBar class="btn" @fooArg=\'barbaz\' />' ,
77- errors : [
78- { message : 'Unnecessary curly braces in string.' } ,
79- { message : 'Unnecessary curly braces in string.' } ,
80- ] ,
81- } ,
82- {
83- code : '<FooBar class="btn">{{"Foo"}}</FooBar>' ,
84- output : '<FooBar class="btn">Foo</FooBar>' ,
85- errors : [ { message : 'Unnecessary curly braces in string.' } ] ,
86- } ,
87- ] ,
66+ valid : validHbs ,
67+ invalid : invalidHbs ,
8868} ) ;
0 commit comments