|
| 1 | +const rule = require('../../../lib/rules/template-no-block-params-for-html-elements'); |
| 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 | + |
| 9 | +ruleTester.run('template-no-block-params-for-html-elements', rule, { |
| 10 | + valid: [ |
| 11 | + `let div = <template>{{yield "hello"}}</template>; |
| 12 | + <template> |
| 13 | + <div as |greeting|>{{greeting}}</div> |
| 14 | + </template> |
| 15 | + `, |
| 16 | + '<template><div>Content</div></template>', |
| 17 | + '<template><MyComponent as |item|>{{item.name}}</MyComponent></template>', |
| 18 | + '<template>{{#each this.items as |item|}}<li>{{item}}</li>{{/each}}</template>', |
| 19 | + '<template><button>Click</button></template>', |
| 20 | + ], |
| 21 | + |
| 22 | + invalid: [ |
| 23 | + { |
| 24 | + code: '<template><div as |content|>{{content}}</div></template>', |
| 25 | + output: null, |
| 26 | + errors: [ |
| 27 | + { |
| 28 | + message: 'Block params can only be used with components, not HTML elements.', |
| 29 | + type: 'GlimmerElementNode', |
| 30 | + }, |
| 31 | + ], |
| 32 | + }, |
| 33 | + { |
| 34 | + code: '<template><section as |data|><p>{{data}}</p></section></template>', |
| 35 | + output: null, |
| 36 | + errors: [ |
| 37 | + { |
| 38 | + message: 'Block params can only be used with components, not HTML elements.', |
| 39 | + type: 'GlimmerElementNode', |
| 40 | + }, |
| 41 | + ], |
| 42 | + }, |
| 43 | + { |
| 44 | + code: '<template><ul as |items|><li>{{items}}</li></ul></template>', |
| 45 | + output: null, |
| 46 | + errors: [ |
| 47 | + { |
| 48 | + message: 'Block params can only be used with components, not HTML elements.', |
| 49 | + type: 'GlimmerElementNode', |
| 50 | + }, |
| 51 | + ], |
| 52 | + }, |
| 53 | + ], |
| 54 | +}); |
0 commit comments