|
| 1 | +const rule = require('../../../lib/rules/template-no-splattributes-with-class'); |
| 2 | +const RuleTester = require('eslint').RuleTester; |
| 3 | + |
| 4 | +const ERROR_MESSAGE = |
| 5 | + 'Using `...attributes` with `class` attribute is not allowed. Use `...attributes` alone to allow class merging.'; |
| 6 | + |
| 7 | +const ruleTester = new RuleTester({ |
| 8 | + parser: require.resolve('ember-eslint-parser'), |
| 9 | + parserOptions: { ecmaVersion: 2022, sourceType: 'module' }, |
| 10 | +}); |
| 11 | + |
| 12 | +ruleTester.run('template-no-splattributes-with-class', rule, { |
| 13 | + valid: [ |
| 14 | + '<template><div ...attributes>content</div></template>', |
| 15 | + '<template><div class="foo">content</div></template>', |
| 16 | + '<template><div class="foo bar">content</div></template>', |
| 17 | + '<template><div class={{foo}}>content</div></template>', |
| 18 | + '<template><div class="foo {{bar}}">content</div></template>', |
| 19 | + ], |
| 20 | + invalid: [ |
| 21 | + { |
| 22 | + code: '<template><div ...attributes class="foo">content</div></template>', |
| 23 | + output: null, |
| 24 | + errors: [{ message: ERROR_MESSAGE }], |
| 25 | + }, |
| 26 | + { |
| 27 | + code: '<template><div class="foo" ...attributes>content</div></template>', |
| 28 | + output: null, |
| 29 | + errors: [{ message: ERROR_MESSAGE }], |
| 30 | + }, |
| 31 | + { |
| 32 | + code: '<template><div ...attributes class={{foo}}>content</div></template>', |
| 33 | + output: null, |
| 34 | + errors: [{ message: ERROR_MESSAGE }], |
| 35 | + }, |
| 36 | + |
| 37 | + { |
| 38 | + code: '<template><div class="foo" ...attributes class="bar">content</div></template>', |
| 39 | + output: null, |
| 40 | + errors: [{ message: ERROR_MESSAGE }], |
| 41 | + }, |
| 42 | + ], |
| 43 | +}); |
| 44 | + |
| 45 | +const hbsRuleTester = new RuleTester({ |
| 46 | + parser: require.resolve('ember-eslint-parser/hbs'), |
| 47 | + parserOptions: { |
| 48 | + ecmaVersion: 2022, |
| 49 | + sourceType: 'module', |
| 50 | + }, |
| 51 | +}); |
| 52 | + |
| 53 | +hbsRuleTester.run('template-no-splattributes-with-class', rule, { |
| 54 | + valid: [ |
| 55 | + '<div ...attributes>content</div>', |
| 56 | + '<div class="foo">content</div>', |
| 57 | + '<div class="foo bar">content</div>', |
| 58 | + '<div class={{foo}}>content</div>', |
| 59 | + '<div class="foo {{bar}}">content</div>', |
| 60 | + ], |
| 61 | + invalid: [ |
| 62 | + { |
| 63 | + code: '<div ...attributes class="foo">content</div>', |
| 64 | + output: null, |
| 65 | + errors: [ |
| 66 | + { |
| 67 | + message: |
| 68 | + 'Using `...attributes` with `class` attribute is not allowed. Use `...attributes` alone to allow class merging.', |
| 69 | + }, |
| 70 | + ], |
| 71 | + }, |
| 72 | + { |
| 73 | + code: '<div class="foo" ...attributes>content</div>', |
| 74 | + output: null, |
| 75 | + errors: [ |
| 76 | + { |
| 77 | + message: |
| 78 | + 'Using `...attributes` with `class` attribute is not allowed. Use `...attributes` alone to allow class merging.', |
| 79 | + }, |
| 80 | + ], |
| 81 | + }, |
| 82 | + { |
| 83 | + code: '<div ...attributes class={{foo}}>content</div>', |
| 84 | + output: null, |
| 85 | + errors: [ |
| 86 | + { |
| 87 | + message: |
| 88 | + 'Using `...attributes` with `class` attribute is not allowed. Use `...attributes` alone to allow class merging.', |
| 89 | + }, |
| 90 | + ], |
| 91 | + }, |
| 92 | + { |
| 93 | + code: '<div class="foo" ...attributes class="bar">content</div>', |
| 94 | + output: null, |
| 95 | + errors: [ |
| 96 | + { |
| 97 | + message: |
| 98 | + 'Using `...attributes` with `class` attribute is not allowed. Use `...attributes` alone to allow class merging.', |
| 99 | + }, |
| 100 | + ], |
| 101 | + }, |
| 102 | + ], |
| 103 | +}); |
0 commit comments