|
| 1 | +//------------------------------------------------------------------------------ |
| 2 | +// Requirements |
| 3 | +//------------------------------------------------------------------------------ |
| 4 | + |
| 5 | +const rule = require('../../../lib/rules/template-no-scope-outside-table-headings'); |
| 6 | +const RuleTester = require('eslint').RuleTester; |
| 7 | + |
| 8 | +const ruleTester = new RuleTester({ |
| 9 | + parser: require.resolve('ember-eslint-parser'), |
| 10 | + parserOptions: { ecmaVersion: 2022, sourceType: 'module' }, |
| 11 | +}); |
| 12 | + |
| 13 | +ruleTester.run('template-no-scope-outside-table-headings', rule, { |
| 14 | + valid: [ |
| 15 | + '<template><th scope="row">Some table heading></th></template>', |
| 16 | + `<template> |
| 17 | + <table> |
| 18 | + <th scope="col">Table header</th> |
| 19 | + <td>Some data</td> |
| 20 | + </table> |
| 21 | + </template>`, |
| 22 | + '<template><CustomComponent scope /></template>', |
| 23 | + '<template><CustomComponent scope="row" /></template>', |
| 24 | + '<template><CustomComponent scope={{foo}} /></template>', |
| 25 | + '<template>{{foo-component scope="row"}}</template>', |
| 26 | + ], |
| 27 | + invalid: [ |
| 28 | + { |
| 29 | + code: '<template><td scope="row"></td></template>', |
| 30 | + output: null, |
| 31 | + errors: [{ messageId: 'noScopeOutsideTableHeadings' }], |
| 32 | + }, |
| 33 | + { |
| 34 | + code: '<template><td scope></td></template>', |
| 35 | + output: null, |
| 36 | + errors: [{ messageId: 'noScopeOutsideTableHeadings' }], |
| 37 | + }, |
| 38 | + { |
| 39 | + code: '<template><a scope="row" /></template>', |
| 40 | + output: null, |
| 41 | + errors: [{ messageId: 'noScopeOutsideTableHeadings' }], |
| 42 | + }, |
| 43 | + { |
| 44 | + code: `<template> |
| 45 | +<table> |
| 46 | +<th>Some header</th> |
| 47 | +<td scope="col">Some data</td> |
| 48 | +</table> |
| 49 | +</template>`, |
| 50 | + output: null, |
| 51 | + errors: [{ messageId: 'noScopeOutsideTableHeadings' }], |
| 52 | + }, |
| 53 | + ], |
| 54 | +}); |
| 55 | + |
| 56 | +const hbsRuleTester = new RuleTester({ |
| 57 | + parser: require.resolve('ember-eslint-parser/hbs'), |
| 58 | + parserOptions: { |
| 59 | + ecmaVersion: 2022, |
| 60 | + sourceType: 'module', |
| 61 | + }, |
| 62 | +}); |
| 63 | + |
| 64 | +hbsRuleTester.run('template-no-scope-outside-table-headings', rule, { |
| 65 | + valid: [ |
| 66 | + '<th scope="row">Some table heading></th>', |
| 67 | + ` |
| 68 | + <table> |
| 69 | + <th scope="col">Table header</th> |
| 70 | + <td>Some data</td> |
| 71 | + </table> |
| 72 | + `, |
| 73 | + '<CustomComponent scope />', |
| 74 | + '<CustomComponent scope="row" />', |
| 75 | + '<CustomComponent scope={{foo}} />', |
| 76 | + '{{foo-component scope="row"}}', |
| 77 | + ], |
| 78 | + invalid: [ |
| 79 | + { |
| 80 | + code: '<td scope="row"></td>', |
| 81 | + output: null, |
| 82 | + errors: [{ message: 'Unexpected scope attribute on <td>. Use only on <th>.' }], |
| 83 | + }, |
| 84 | + { |
| 85 | + code: '<td scope></td>', |
| 86 | + output: null, |
| 87 | + errors: [{ message: 'Unexpected scope attribute on <td>. Use only on <th>.' }], |
| 88 | + }, |
| 89 | + { |
| 90 | + code: '<a scope="row" />', |
| 91 | + output: null, |
| 92 | + errors: [{ message: 'Unexpected scope attribute on <a>. Use only on <th>.' }], |
| 93 | + }, |
| 94 | + { |
| 95 | + code: ` |
| 96 | +<table> |
| 97 | +<th>Some header</th> |
| 98 | +<td scope="col">Some data</td> |
| 99 | +</table> |
| 100 | +`, |
| 101 | + output: null, |
| 102 | + errors: [{ message: 'Unexpected scope attribute on <td>. Use only on <th>.' }], |
| 103 | + }, |
| 104 | + ], |
| 105 | +}); |
0 commit comments