11const rule = require ( '../../../lib/rules/template-no-unbound' ) ;
22const RuleTester = require ( 'eslint' ) . RuleTester ;
33
4- const ruleTester = new RuleTester ( {
4+ const validHbs = [ '{{foo}}' , '{{button}}' ] ;
5+
6+ const invalidHbs = [
7+ {
8+ code : '{{unbound foo}}' ,
9+ output : null ,
10+ errors : [ { message : 'Unexpected {{unbound}} usage.' } ] ,
11+ } ,
12+ {
13+ code : '{{my-thing foo=(unbound foo)}}' ,
14+ output : null ,
15+ errors : [ { message : 'Unexpected {{unbound}} usage.' } ] ,
16+ } ,
17+ ] ;
18+
19+ function wrapTemplate ( entry ) {
20+ if ( typeof entry === 'string' ) {
21+ return `<template>${ entry } </template>` ;
22+ }
23+
24+ return {
25+ ...entry ,
26+ code : `<template>${ entry . code } </template>` ,
27+ output : entry . output ? `<template>${ entry . output } </template>` : entry . output ,
28+ errors : entry . errors . map ( ( ) => ( { messageId : 'unexpected' } ) ) ,
29+ } ;
30+ }
31+
32+ const gjsRuleTester = new RuleTester ( {
533 parser : require . resolve ( 'ember-eslint-parser' ) ,
634 parserOptions : { ecmaVersion : 2022 , sourceType : 'module' } ,
735} ) ;
8- ruleTester . run ( 'template-no-unbound' , rule , {
9- valid : [
10- '<template>{{this.value}}</template>' ,
11- '<template>{{foo}}</template>' ,
12- '<template>{{button}}</template>' ,
13- ] ,
14- invalid : [
15- {
16- code : '<template>{{unbound foo}}</template>' ,
17- output : null ,
18- errors : [ { messageId : 'unexpected' } ] ,
19- } ,
20-
21- {
22- code : '<template>{{my-thing foo=(unbound foo)}}</template>' ,
23- output : null ,
24- errors : [ { messageId : 'unexpected' } ] ,
25- } ,
26- ] ,
36+
37+ gjsRuleTester . run ( 'template-no-unbound' , rule , {
38+ valid : validHbs . map ( wrapTemplate ) ,
39+ invalid : invalidHbs . map ( wrapTemplate ) ,
2740} ) ;
2841
2942const hbsRuleTester = new RuleTester ( {
@@ -35,17 +48,6 @@ const hbsRuleTester = new RuleTester({
3548} ) ;
3649
3750hbsRuleTester . run ( 'template-no-unbound' , rule , {
38- valid : [ '{{foo}}' , '{{button}}' ] ,
39- invalid : [
40- {
41- code : '{{unbound foo}}' ,
42- output : null ,
43- errors : [ { message : 'Unexpected unbound helper usage.' } ] ,
44- } ,
45- {
46- code : '{{my-thing foo=(unbound foo)}}' ,
47- output : null ,
48- errors : [ { message : 'Unexpected unbound helper usage.' } ] ,
49- } ,
50- ] ,
51+ valid : validHbs ,
52+ invalid : invalidHbs ,
5153} ) ;
0 commit comments