|
| 1 | +const { RuleTester } = require('eslint'); |
| 2 | +const rule = require('../../../lib/rules/template-no-potential-path-strings'); |
| 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-potential-path-strings', rule, { |
| 10 | + valid: [ |
| 11 | + '<template><img src="foo.png"></template>', |
| 12 | + '<template><img src={{picture}}></template>', |
| 13 | + '<template><img src={{this.picture}}></template>', |
| 14 | + '<template><img src={{@img}}></template>', |
| 15 | + '<template><SomeComponent @foo={{@bar}} /></template>', |
| 16 | + '<template><Ui::Demo @title="@my-org/my-package" /></template>', |
| 17 | + '<template><Ui::Demo @title="@my-org\\my-package" /></template>', |
| 18 | + '<template><Ui::Demo @title="@my-org|my-package" /></template>', |
| 19 | + ], |
| 20 | + |
| 21 | + invalid: [ |
| 22 | + { |
| 23 | + code: '<template><img src="this.picture"></template>', |
| 24 | + output: null, |
| 25 | + errors: [ |
| 26 | + { |
| 27 | + message: 'Potential path in attribute string detected. Did you mean {{this.picture}}?', |
| 28 | + }, |
| 29 | + ], |
| 30 | + }, |
| 31 | + { |
| 32 | + code: '<template><img src=this.picture></template>', |
| 33 | + output: null, |
| 34 | + errors: [ |
| 35 | + { |
| 36 | + message: 'Potential path in attribute string detected. Did you mean {{this.picture}}?', |
| 37 | + }, |
| 38 | + ], |
| 39 | + }, |
| 40 | + { |
| 41 | + code: '<template><img src="@img"></template>', |
| 42 | + output: null, |
| 43 | + errors: [ |
| 44 | + { |
| 45 | + message: 'Potential path in attribute string detected. Did you mean {{@img}}?', |
| 46 | + }, |
| 47 | + ], |
| 48 | + }, |
| 49 | + { |
| 50 | + code: '<template><img src=@img></template>', |
| 51 | + output: null, |
| 52 | + errors: [ |
| 53 | + { |
| 54 | + message: 'Potential path in attribute string detected. Did you mean {{@img}}?', |
| 55 | + }, |
| 56 | + ], |
| 57 | + }, |
| 58 | + { |
| 59 | + code: '<template><SomeComponent @foo=@bar /></template>', |
| 60 | + output: null, |
| 61 | + errors: [ |
| 62 | + { |
| 63 | + message: 'Potential path in attribute string detected. Did you mean {{@bar}}?', |
| 64 | + }, |
| 65 | + ], |
| 66 | + }, |
| 67 | + { |
| 68 | + code: '<template><SomeComponent @foo=this.bar /></template>', |
| 69 | + output: null, |
| 70 | + errors: [ |
| 71 | + { |
| 72 | + message: 'Potential path in attribute string detected. Did you mean {{this.bar}}?', |
| 73 | + }, |
| 74 | + ], |
| 75 | + }, |
| 76 | + ], |
| 77 | +}); |
| 78 | + |
| 79 | +const hbsRuleTester = new RuleTester({ |
| 80 | + parser: require.resolve('ember-eslint-parser/hbs'), |
| 81 | + parserOptions: { |
| 82 | + ecmaVersion: 2022, |
| 83 | + sourceType: 'module', |
| 84 | + }, |
| 85 | +}); |
| 86 | + |
| 87 | +hbsRuleTester.run('template-no-potential-path-strings', rule, { |
| 88 | + valid: [ |
| 89 | + '<img src="foo.png">', |
| 90 | + '<img src={{picture}}>', |
| 91 | + '<img src={{this.picture}}>', |
| 92 | + '<img src={{@img}}>', |
| 93 | + '<SomeComponent @foo={{@bar}} />', |
| 94 | + '<Ui::Demo @title="@my-org/my-package" />', |
| 95 | + '<Ui::Demo @title="@my-org\\my-package" />', |
| 96 | + '<Ui::Demo @title="@my-org|my-package" />', |
| 97 | + ], |
| 98 | + invalid: [ |
| 99 | + { |
| 100 | + code: '<img src="this.picture">', |
| 101 | + output: null, |
| 102 | + errors: [ |
| 103 | + { |
| 104 | + message: 'Potential path in attribute string detected. Did you mean {{this.picture}}?', |
| 105 | + }, |
| 106 | + ], |
| 107 | + }, |
| 108 | + { |
| 109 | + code: '<img src=this.picture>', |
| 110 | + output: null, |
| 111 | + errors: [ |
| 112 | + { |
| 113 | + message: 'Potential path in attribute string detected. Did you mean {{this.picture}}?', |
| 114 | + }, |
| 115 | + ], |
| 116 | + }, |
| 117 | + { |
| 118 | + code: '<img src="@img">', |
| 119 | + output: null, |
| 120 | + errors: [ |
| 121 | + { |
| 122 | + message: 'Potential path in attribute string detected. Did you mean {{@img}}?', |
| 123 | + }, |
| 124 | + ], |
| 125 | + }, |
| 126 | + { |
| 127 | + code: '<img src=@img>', |
| 128 | + output: null, |
| 129 | + errors: [ |
| 130 | + { |
| 131 | + message: 'Potential path in attribute string detected. Did you mean {{@img}}?', |
| 132 | + }, |
| 133 | + ], |
| 134 | + }, |
| 135 | + { |
| 136 | + code: '<SomeComponent @foo=@bar />', |
| 137 | + output: null, |
| 138 | + errors: [ |
| 139 | + { |
| 140 | + message: 'Potential path in attribute string detected. Did you mean {{@bar}}?', |
| 141 | + }, |
| 142 | + ], |
| 143 | + }, |
| 144 | + { |
| 145 | + code: '<SomeComponent @foo=this.bar />', |
| 146 | + output: null, |
| 147 | + errors: [ |
| 148 | + { |
| 149 | + message: 'Potential path in attribute string detected. Did you mean {{this.bar}}?', |
| 150 | + }, |
| 151 | + ], |
| 152 | + }, |
| 153 | + ], |
| 154 | +}); |
0 commit comments