|
| 1 | +const rule = require('../../../lib/rules/template-no-extra-mut-helper-argument'); |
| 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-extra-mut-helper-argument', rule, { |
| 10 | + valid: [ |
| 11 | + '<template>{{my-component click=(action (mut isClicked))}}</template>', |
| 12 | + '<template>{{my-component click=(action (mut isClicked) true)}}</template>', |
| 13 | + '<template>{{my-component isClickedMutable=(mut isClicked)}}</template>', |
| 14 | + '<template><button {{action (mut isClicked)}}></button></template>', |
| 15 | + '<template><button {{action (mut isClicked) true}}></button></template>', |
| 16 | + ], |
| 17 | + invalid: [ |
| 18 | + { |
| 19 | + code: '<template>{{my-component click=(action (mut isClicked true))}}</template>', |
| 20 | + output: null, |
| 21 | + errors: [ |
| 22 | + { |
| 23 | + message: |
| 24 | + 'The handlebars `mut(attr)` helper should only have one argument passed to it. To pass a value, use: `(action (mut attr) value)`.', |
| 25 | + }, |
| 26 | + ], |
| 27 | + }, |
| 28 | + { |
| 29 | + code: '<template>{{my-component isClickedMutable=(mut isClicked true)}}</template>', |
| 30 | + output: null, |
| 31 | + errors: [ |
| 32 | + { |
| 33 | + message: |
| 34 | + 'The handlebars `mut(attr)` helper should only have one argument passed to it. To pass a value, use: `(action (mut attr) value)`.', |
| 35 | + }, |
| 36 | + ], |
| 37 | + }, |
| 38 | + { |
| 39 | + code: '<template><button {{action (mut isClicked true)}}></button></template>', |
| 40 | + output: null, |
| 41 | + errors: [ |
| 42 | + { |
| 43 | + message: |
| 44 | + 'The handlebars `mut(attr)` helper should only have one argument passed to it. To pass a value, use: `(action (mut attr) value)`.', |
| 45 | + }, |
| 46 | + ], |
| 47 | + }, |
| 48 | + ], |
| 49 | +}); |
| 50 | + |
| 51 | +const hbsRuleTester = new RuleTester({ |
| 52 | + parser: require.resolve('ember-eslint-parser/hbs'), |
| 53 | + parserOptions: { |
| 54 | + ecmaVersion: 2022, |
| 55 | + sourceType: 'module', |
| 56 | + }, |
| 57 | +}); |
| 58 | + |
| 59 | +hbsRuleTester.run('template-no-extra-mut-helper-argument', rule, { |
| 60 | + valid: [ |
| 61 | + '{{my-component click=(action (mut isClicked))}}', |
| 62 | + '{{my-component click=(action (mut isClicked) true)}}', |
| 63 | + '{{my-component isClickedMutable=(mut isClicked)}}', |
| 64 | + '<button {{action (mut isClicked)}}></button>', |
| 65 | + '<button {{action (mut isClicked) true}}></button>', |
| 66 | + ], |
| 67 | + invalid: [ |
| 68 | + { |
| 69 | + code: '{{my-component click=(action (mut isClicked true))}}', |
| 70 | + output: null, |
| 71 | + errors: [ |
| 72 | + { |
| 73 | + message: |
| 74 | + 'The handlebars `mut(attr)` helper should only have one argument passed to it. To pass a value, use: `(action (mut attr) value)`.', |
| 75 | + }, |
| 76 | + ], |
| 77 | + }, |
| 78 | + { |
| 79 | + code: '{{my-component isClickedMutable=(mut isClicked true)}}', |
| 80 | + output: null, |
| 81 | + errors: [ |
| 82 | + { |
| 83 | + message: |
| 84 | + 'The handlebars `mut(attr)` helper should only have one argument passed to it. To pass a value, use: `(action (mut attr) value)`.', |
| 85 | + }, |
| 86 | + ], |
| 87 | + }, |
| 88 | + { |
| 89 | + code: '<button {{action (mut isClicked true)}}></button>', |
| 90 | + output: null, |
| 91 | + errors: [ |
| 92 | + { |
| 93 | + message: |
| 94 | + 'The handlebars `mut(attr)` helper should only have one argument passed to it. To pass a value, use: `(action (mut attr) value)`.', |
| 95 | + }, |
| 96 | + ], |
| 97 | + }, |
| 98 | + ], |
| 99 | +}); |
0 commit comments