|
| 1 | +const rule = require('../../../lib/rules/template-deprecated-inline-view-helper'); |
| 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-deprecated-inline-view-helper', rule, { |
| 10 | + valid: [ |
| 11 | + '<template><MyComponent /></template>', |
| 12 | + '<template>{{view}}</template>', |
| 13 | + '<template>{{great-fishsticks}}</template>', |
| 14 | + '<template>{{input placeholder=(t "email") value=email}}</template>', |
| 15 | + '<template>{{title "CrossCheck Web" prepend=true separator=" | "}}</template>', |
| 16 | + '<template>{{false}}</template>', |
| 17 | + '<template>{{"foo"}}</template>', |
| 18 | + '<template>{{42}}</template>', |
| 19 | + '<template>{{null}}</template>', |
| 20 | + '<template>{{undefined}}</template>', |
| 21 | + '<template>{{has-block "view"}}</template>', |
| 22 | + '<template>{{yield to="view"}}</template>', |
| 23 | + '<template>{{#if (has-block "view")}}{{yield to="view"}}{{/if}}</template>', |
| 24 | + '<template>{{this.view}}</template>', |
| 25 | + '<template>{{@view}}</template>', |
| 26 | + '<template>{{#let this.prop as |view|}} {{view}} {{/let}}</template>', |
| 27 | + ], |
| 28 | + invalid: [ |
| 29 | + { |
| 30 | + code: '<template>{{view class="foo"}}</template>', |
| 31 | + output: null, |
| 32 | + errors: [{ messageId: 'deprecated' }], |
| 33 | + }, |
| 34 | + |
| 35 | + { |
| 36 | + code: "<template>{{view 'awful-fishsticks'}}</template>", |
| 37 | + output: null, |
| 38 | + errors: [{ messageId: 'deprecated' }], |
| 39 | + }, |
| 40 | + { |
| 41 | + code: '<template>{{view.bad-fishsticks}}</template>', |
| 42 | + output: null, |
| 43 | + errors: [{ messageId: 'deprecated' }], |
| 44 | + }, |
| 45 | + { |
| 46 | + code: '<template>{{view.terrible.fishsticks}}</template>', |
| 47 | + output: null, |
| 48 | + errors: [{ messageId: 'deprecated' }], |
| 49 | + }, |
| 50 | + { |
| 51 | + code: '<template>{{foo-bar bab=good baz=view.qux.qaz boo=okay}}</template>', |
| 52 | + output: null, |
| 53 | + errors: [{ messageId: 'deprecated' }], |
| 54 | + }, |
| 55 | + { |
| 56 | + code: '<template><div class="whatever-class" data-foo={{view.hallo}} sure=thing></div></template>', |
| 57 | + output: null, |
| 58 | + errors: [{ messageId: 'deprecated' }], |
| 59 | + }, |
| 60 | + { |
| 61 | + code: '<template>{{#foo-bar derp=view.whoops thing=whatever}}{{/foo-bar}}</template>', |
| 62 | + output: null, |
| 63 | + errors: [{ messageId: 'deprecated' }], |
| 64 | + }, |
| 65 | + ], |
| 66 | +}); |
| 67 | + |
| 68 | +const hbsRuleTester = new RuleTester({ |
| 69 | + parser: require.resolve('ember-eslint-parser/hbs'), |
| 70 | + parserOptions: { |
| 71 | + ecmaVersion: 2022, |
| 72 | + sourceType: 'module', |
| 73 | + }, |
| 74 | +}); |
| 75 | + |
| 76 | +hbsRuleTester.run('template-deprecated-inline-view-helper', rule, { |
| 77 | + valid: [ |
| 78 | + '{{great-fishsticks}}', |
| 79 | + '{{input placeholder=(t "email") value=email}}', |
| 80 | + '{{title "CrossCheck Web" prepend=true separator=" | "}}', |
| 81 | + '{{false}}', |
| 82 | + '{{"foo"}}', |
| 83 | + '{{42}}', |
| 84 | + '{{null}}', |
| 85 | + '{{undefined}}', |
| 86 | + '{{has-block "view"}}', |
| 87 | + '{{yield to="view"}}', |
| 88 | + '{{#if (has-block "view")}}{{yield to="view"}}{{/if}}', |
| 89 | + '{{this.view}}', |
| 90 | + '{{@view}}', |
| 91 | + '{{#let this.prop as |view|}} {{view}} {{/let}}', |
| 92 | + ], |
| 93 | + invalid: [ |
| 94 | + { |
| 95 | + code: "{{view 'awful-fishsticks'}}", |
| 96 | + output: null, |
| 97 | + errors: [ |
| 98 | + { |
| 99 | + message: |
| 100 | + 'The inline form of `view` is deprecated. Please use `Ember.Component` instead. See http://emberjs.com/deprecations/v1.x/#toc_ember-view', |
| 101 | + }, |
| 102 | + ], |
| 103 | + }, |
| 104 | + { |
| 105 | + code: '{{view.bad-fishsticks}}', |
| 106 | + output: null, |
| 107 | + errors: [ |
| 108 | + { |
| 109 | + message: |
| 110 | + 'The inline form of `view` is deprecated. Please use `Ember.Component` instead. See http://emberjs.com/deprecations/v1.x/#toc_ember-view', |
| 111 | + }, |
| 112 | + ], |
| 113 | + }, |
| 114 | + { |
| 115 | + code: '{{view.terrible.fishsticks}}', |
| 116 | + output: null, |
| 117 | + errors: [ |
| 118 | + { |
| 119 | + message: |
| 120 | + 'The inline form of `view` is deprecated. Please use `Ember.Component` instead. See http://emberjs.com/deprecations/v1.x/#toc_ember-view', |
| 121 | + }, |
| 122 | + ], |
| 123 | + }, |
| 124 | + { |
| 125 | + code: '{{foo-bar bab=good baz=view.qux.qaz boo=okay}}', |
| 126 | + output: null, |
| 127 | + errors: [ |
| 128 | + { |
| 129 | + message: |
| 130 | + 'The inline form of `view` is deprecated. Please use `Ember.Component` instead. See http://emberjs.com/deprecations/v1.x/#toc_ember-view', |
| 131 | + }, |
| 132 | + ], |
| 133 | + }, |
| 134 | + { |
| 135 | + code: '<div class="whatever-class" data-foo={{view.hallo}} sure=thing></div>', |
| 136 | + output: null, |
| 137 | + errors: [ |
| 138 | + { |
| 139 | + message: |
| 140 | + 'The inline form of `view` is deprecated. Please use `Ember.Component` instead. See http://emberjs.com/deprecations/v1.x/#toc_ember-view', |
| 141 | + }, |
| 142 | + ], |
| 143 | + }, |
| 144 | + { |
| 145 | + code: '{{#foo-bar derp=view.whoops thing=whatever}}{{/foo-bar}}', |
| 146 | + output: null, |
| 147 | + errors: [ |
| 148 | + { |
| 149 | + message: |
| 150 | + 'The inline form of `view` is deprecated. Please use `Ember.Component` instead. See http://emberjs.com/deprecations/v1.x/#toc_ember-view', |
| 151 | + }, |
| 152 | + ], |
| 153 | + }, |
| 154 | + ], |
| 155 | +}); |
0 commit comments