|
| 1 | +const rule = require('../../../lib/rules/template-no-unnecessary-curly-strings'); |
| 2 | +const RuleTester = require('eslint').RuleTester; |
| 3 | + |
| 4 | +const ruleTester = new RuleTester({ |
| 5 | + parser: require.resolve('ember-eslint-parser'), |
| 6 | + parserOptions: { ecmaVersion: 2022, sourceType: 'module' }, |
| 7 | +}); |
| 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 | + }, |
| 33 | + |
| 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 | + ], |
| 45 | +}); |
| 46 | + |
| 47 | +const hbsRuleTester = new RuleTester({ |
| 48 | + parser: require.resolve('ember-eslint-parser/hbs'), |
| 49 | + parserOptions: { |
| 50 | + ecmaVersion: 2022, |
| 51 | + sourceType: 'module', |
| 52 | + }, |
| 53 | +}); |
| 54 | + |
| 55 | +hbsRuleTester.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 | + ], |
| 88 | +}); |
0 commit comments