|
| 1 | +const rule = require('../../../lib/rules/template-no-quoteless-attributes'); |
| 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 | +ruleTester.run('template-no-quoteless-attributes', rule, { |
| 9 | + valid: [ |
| 10 | + '<template><div class="foo"></div></template>', |
| 11 | + '<template><div data-foo="derp"></div></template>', |
| 12 | + '<template><div data-foo="derp {{stuff}}"></div></template>', |
| 13 | + '<template><div data-foo={{someValue}}></div></template>', |
| 14 | + '<template><div data-foo={{true}}></div></template>', |
| 15 | + '<template><div data-foo={{false}}></div></template>', |
| 16 | + '<template><div data-foo={{5}}></div></template>', |
| 17 | + '<template><SomeThing ...attributes /></template>', |
| 18 | + '<template><div></div></template>', |
| 19 | + '<template><input disabled></template>', |
| 20 | + ], |
| 21 | + invalid: [ |
| 22 | + { |
| 23 | + code: '<template><div class=foo></div></template>', |
| 24 | + output: '<template><div class="foo"></div></template>', |
| 25 | + errors: [{ messageId: 'missing' }], |
| 26 | + }, |
| 27 | + |
| 28 | + { |
| 29 | + code: '<template><div data-foo=asdf></div></template>', |
| 30 | + output: '<template><div data-foo="asdf"></div></template>', |
| 31 | + errors: [{ messageId: 'missing' }], |
| 32 | + }, |
| 33 | + { |
| 34 | + code: '<template><SomeThing @blah=asdf /></template>', |
| 35 | + output: '<template><SomeThing @blah="asdf" /></template>', |
| 36 | + errors: [{ messageId: 'missing' }], |
| 37 | + }, |
| 38 | + ], |
| 39 | +}); |
| 40 | + |
| 41 | +const hbsRuleTester = new RuleTester({ |
| 42 | + parser: require.resolve('ember-eslint-parser/hbs'), |
| 43 | + parserOptions: { |
| 44 | + ecmaVersion: 2022, |
| 45 | + sourceType: 'module', |
| 46 | + }, |
| 47 | +}); |
| 48 | + |
| 49 | +hbsRuleTester.run('template-no-quoteless-attributes', rule, { |
| 50 | + valid: [ |
| 51 | + '<div data-foo="derp"></div>', |
| 52 | + '<div data-foo="derp {{stuff}}"></div>', |
| 53 | + '<div data-foo={{someValue}}></div>', |
| 54 | + '<div data-foo={{true}}></div>', |
| 55 | + '<div data-foo={{false}}></div>', |
| 56 | + '<div data-foo={{5}}></div>', |
| 57 | + '<SomeThing ...attributes />', |
| 58 | + '<div></div>', |
| 59 | + '<input disabled>', |
| 60 | + ], |
| 61 | + invalid: [ |
| 62 | + { |
| 63 | + code: '<div data-foo=asdf></div>', |
| 64 | + output: '<div data-foo="asdf"></div>', |
| 65 | + errors: [{ message: 'Attribute data-foo should be either quoted or wrapped in mustaches' }], |
| 66 | + }, |
| 67 | + { |
| 68 | + code: '<SomeThing @blah=asdf />', |
| 69 | + output: '<SomeThing @blah="asdf" />', |
| 70 | + errors: [{ message: 'Argument @blah should be either quoted or wrapped in mustaches' }], |
| 71 | + }, |
| 72 | + ], |
| 73 | +}); |
0 commit comments