|
| 1 | +const rule = require('../../../lib/rules/template-no-index-component-invocation'); |
| 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-index-component-invocation', rule, { |
| 10 | + valid: [ |
| 11 | + '<template><Foo::Bar /></template>', |
| 12 | + '<template><Foo::IndexItem /></template>', |
| 13 | + '<template><Foo::MyIndex /></template>', |
| 14 | + '<template><Foo::MyIndex></Foo::MyIndex></template>', |
| 15 | + '<template>{{foo/index-item}}</template>', |
| 16 | + '<template>{{foo/my-index}}</template>', |
| 17 | + '<template>{{foo/bar}}</template>', |
| 18 | + '<template>{{#foo/bar}}{{/foo/bar}}</template>', |
| 19 | + '<template>{{component "foo/bar"}}</template>', |
| 20 | + '<template>{{component "foo/my-index"}}</template>', |
| 21 | + '<template>{{component "foo/index-item"}}</template>', |
| 22 | + '<template>{{#component "foo/index-item"}}{{/component}}</template>', |
| 23 | + ], |
| 24 | + invalid: [ |
| 25 | + { |
| 26 | + code: '<template>{{foo/index}}</template>', |
| 27 | + output: null, |
| 28 | + errors: [ |
| 29 | + { |
| 30 | + message: 'Replace `{{foo/index ...` to `{{foo ...`', |
| 31 | + }, |
| 32 | + ], |
| 33 | + }, |
| 34 | + { |
| 35 | + code: '<template>{{component "foo/index"}}</template>', |
| 36 | + output: null, |
| 37 | + errors: [ |
| 38 | + { |
| 39 | + message: 'Replace `{{component "foo/index" ...` to `{{component "foo" ...`', |
| 40 | + }, |
| 41 | + ], |
| 42 | + }, |
| 43 | + { |
| 44 | + code: '<template>{{#foo/index}}{{/foo/index}}</template>', |
| 45 | + output: null, |
| 46 | + errors: [ |
| 47 | + { |
| 48 | + message: 'Replace `{{#foo/index ...` to `{{#foo ...`', |
| 49 | + }, |
| 50 | + ], |
| 51 | + }, |
| 52 | + { |
| 53 | + code: '<template>{{#component "foo/index"}}{{/component}}</template>', |
| 54 | + output: null, |
| 55 | + errors: [ |
| 56 | + { |
| 57 | + message: 'Replace `{{#component "foo/index" ...` to `{{#component "foo" ...`', |
| 58 | + }, |
| 59 | + ], |
| 60 | + }, |
| 61 | + { |
| 62 | + code: '<template><Foo::Index /></template>', |
| 63 | + output: null, |
| 64 | + errors: [ |
| 65 | + { |
| 66 | + message: 'Replace `<Foo::Index ...` to `<Foo ...`', |
| 67 | + }, |
| 68 | + ], |
| 69 | + }, |
| 70 | + { |
| 71 | + code: '<template><Foo::Index></Foo::Index></template>', |
| 72 | + output: null, |
| 73 | + errors: [ |
| 74 | + { |
| 75 | + message: 'Replace `<Foo::Index ...` to `<Foo ...`', |
| 76 | + }, |
| 77 | + ], |
| 78 | + }, |
| 79 | + |
| 80 | + { |
| 81 | + code: '<template>{{foo/bar (component "foo/index")}}</template>', |
| 82 | + output: null, |
| 83 | + errors: [{ message: 'Replace `(component "foo/index" ...` to `(component "foo" ...`' }], |
| 84 | + }, |
| 85 | + { |
| 86 | + code: '<template>{{foo/bar name=(component "foo/index")}}</template>', |
| 87 | + output: null, |
| 88 | + errors: [{ message: 'Replace `(component "foo/index" ...` to `(component "foo" ...`' }], |
| 89 | + }, |
| 90 | + { |
| 91 | + code: '<template><Foo::Bar::Index /></template>', |
| 92 | + output: null, |
| 93 | + errors: [{ message: 'Replace `<Foo::Bar::Index ...` to `<Foo::Bar ...`' }], |
| 94 | + }, |
| 95 | + ], |
| 96 | +}); |
| 97 | + |
| 98 | +const hbsRuleTester = new RuleTester({ |
| 99 | + parser: require.resolve('ember-eslint-parser/hbs'), |
| 100 | + parserOptions: { |
| 101 | + ecmaVersion: 2022, |
| 102 | + sourceType: 'module', |
| 103 | + }, |
| 104 | +}); |
| 105 | + |
| 106 | +hbsRuleTester.run('template-no-index-component-invocation', rule, { |
| 107 | + valid: [ |
| 108 | + '<Foo::Bar />', |
| 109 | + '<Foo::IndexItem />', |
| 110 | + '<Foo::MyIndex />', |
| 111 | + '<Foo::MyIndex></Foo::MyIndex>', |
| 112 | + '{{foo/index-item}}', |
| 113 | + '{{foo/my-index}}', |
| 114 | + '{{foo/bar}}', |
| 115 | + '{{#foo/bar}}{{/foo/bar}}', |
| 116 | + '{{component "foo/bar"}}', |
| 117 | + '{{component "foo/my-index"}}', |
| 118 | + '{{component "foo/index-item"}}', |
| 119 | + '{{#component "foo/index-item"}}{{/component}}', |
| 120 | + ], |
| 121 | + invalid: [ |
| 122 | + { |
| 123 | + code: '{{foo/index}}', |
| 124 | + output: null, |
| 125 | + errors: [{ message: 'Replace `{{foo/index ...` to `{{foo ...`' }], |
| 126 | + }, |
| 127 | + { |
| 128 | + code: '{{component "foo/index"}}', |
| 129 | + output: null, |
| 130 | + errors: [{ message: 'Replace `{{component "foo/index" ...` to `{{component "foo" ...`' }], |
| 131 | + }, |
| 132 | + { |
| 133 | + code: '{{#foo/index}}{{/foo/index}}', |
| 134 | + output: null, |
| 135 | + errors: [{ message: 'Replace `{{#foo/index ...` to `{{#foo ...`' }], |
| 136 | + }, |
| 137 | + { |
| 138 | + code: '{{#component "foo/index"}}{{/component}}', |
| 139 | + output: null, |
| 140 | + errors: [{ message: 'Replace `{{#component "foo/index" ...` to `{{#component "foo" ...`' }], |
| 141 | + }, |
| 142 | + { |
| 143 | + code: '{{foo/bar (component "foo/index")}}', |
| 144 | + output: null, |
| 145 | + errors: [{ message: 'Replace `(component "foo/index" ...` to `(component "foo" ...`' }], |
| 146 | + }, |
| 147 | + { |
| 148 | + code: '{{foo/bar name=(component "foo/index")}}', |
| 149 | + output: null, |
| 150 | + errors: [{ message: 'Replace `(component "foo/index" ...` to `(component "foo" ...`' }], |
| 151 | + }, |
| 152 | + { |
| 153 | + code: '<Foo::Index />', |
| 154 | + output: null, |
| 155 | + errors: [{ message: 'Replace `<Foo::Index ...` to `<Foo ...`' }], |
| 156 | + }, |
| 157 | + { |
| 158 | + code: '<Foo::Bar::Index />', |
| 159 | + output: null, |
| 160 | + errors: [{ message: 'Replace `<Foo::Bar::Index ...` to `<Foo::Bar ...`' }], |
| 161 | + }, |
| 162 | + { |
| 163 | + code: '<Foo::Index></Foo::Index>', |
| 164 | + output: null, |
| 165 | + errors: [{ message: 'Replace `<Foo::Index ...` to `<Foo ...`' }], |
| 166 | + }, |
| 167 | + ], |
| 168 | +}); |
0 commit comments