|
| 1 | +const rule = require('../../../lib/rules/template-no-link-to-tagname'); |
| 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-link-to-tagname', rule, { |
| 10 | + valid: [ |
| 11 | + { |
| 12 | + filename: 'test.gjs', |
| 13 | + code: '<template><LinkTo @route="index">Home</LinkTo></template>', |
| 14 | + output: null, |
| 15 | + }, |
| 16 | + { |
| 17 | + filename: 'test.gjs', |
| 18 | + code: '<template><link-to @route="about">About</link-to></template>', |
| 19 | + output: null, |
| 20 | + }, |
| 21 | + { |
| 22 | + filename: 'test.gjs', |
| 23 | + code: '<template><a href="/home">Home</a></template>', |
| 24 | + output: null, |
| 25 | + }, |
| 26 | + |
| 27 | + '<template><Foo @route="routeName" @tagName="button">Link text</Foo></template>', |
| 28 | + '<template><LinkTo @route="routeName">Link text</LinkTo></template>', |
| 29 | + '<template>{{#link-to "routeName"}}Link text{{/link-to}}</template>', |
| 30 | + '<template>{{#foo "routeName" tagName="button"}}Link text{{/foo}}</template>', |
| 31 | + '<template>{{link-to "Link text" "routeName"}}</template>', |
| 32 | + '<template>{{foo "Link text" "routeName" tagName="button"}}</template>', |
| 33 | + ], |
| 34 | + |
| 35 | + invalid: [ |
| 36 | + { |
| 37 | + filename: 'test.gjs', |
| 38 | + code: '<template><LinkTo @route="index" tagName="button">Home</LinkTo></template>', |
| 39 | + output: null, |
| 40 | + errors: [{ messageId: 'noLinkToTagname' }], |
| 41 | + }, |
| 42 | + { |
| 43 | + filename: 'test.gjs', |
| 44 | + code: '<template><LinkTo @route="about" @tagName="span">About</LinkTo></template>', |
| 45 | + output: null, |
| 46 | + errors: [{ messageId: 'noLinkToTagname' }], |
| 47 | + }, |
| 48 | + { |
| 49 | + filename: 'test.gjs', |
| 50 | + code: '<template><link-to @route="contact" tagName="div">Contact</link-to></template>', |
| 51 | + output: null, |
| 52 | + errors: [{ messageId: 'noLinkToTagname' }], |
| 53 | + }, |
| 54 | + |
| 55 | + { |
| 56 | + code: '<template><LinkTo @route="routeName" @tagName="button">Link text</LinkTo></template>', |
| 57 | + output: null, |
| 58 | + errors: [{ messageId: 'noLinkToTagname' }], |
| 59 | + }, |
| 60 | + { |
| 61 | + code: '<template>{{#link-to "routeName" tagName="button"}}Link text{{/link-to}}</template>', |
| 62 | + output: null, |
| 63 | + errors: [{ messageId: 'noLinkToTagname' }], |
| 64 | + }, |
| 65 | + { |
| 66 | + code: '<template>{{link-to "Link text" "routeName" tagName="button"}}</template>', |
| 67 | + output: null, |
| 68 | + errors: [{ messageId: 'noLinkToTagname' }], |
| 69 | + }, |
| 70 | + ], |
| 71 | +}); |
| 72 | + |
| 73 | +const hbsRuleTester = new RuleTester({ |
| 74 | + parser: require.resolve('ember-eslint-parser/hbs'), |
| 75 | + parserOptions: { |
| 76 | + ecmaVersion: 2022, |
| 77 | + sourceType: 'module', |
| 78 | + }, |
| 79 | +}); |
| 80 | + |
| 81 | +hbsRuleTester.run('template-no-link-to-tagname', rule, { |
| 82 | + valid: [ |
| 83 | + '<Foo @route="routeName" @tagName="button">Link text</Foo>', |
| 84 | + '<LinkTo @route="routeName">Link text</LinkTo>', |
| 85 | + '{{#link-to "routeName"}}Link text{{/link-to}}', |
| 86 | + '{{#foo "routeName" tagName="button"}}Link text{{/foo}}', |
| 87 | + '{{link-to "Link text" "routeName"}}', |
| 88 | + '{{foo "Link text" "routeName" tagName="button"}}', |
| 89 | + ], |
| 90 | + invalid: [ |
| 91 | + { |
| 92 | + code: '<LinkTo @route="routeName" @tagName="button">Link text</LinkTo>', |
| 93 | + output: null, |
| 94 | + errors: [{ message: 'tagName attribute on LinkTo is deprecated' }], |
| 95 | + }, |
| 96 | + { |
| 97 | + code: '{{#link-to "routeName" tagName="button"}}Link text{{/link-to}}', |
| 98 | + output: null, |
| 99 | + errors: [{ message: 'tagName attribute on LinkTo is deprecated' }], |
| 100 | + }, |
| 101 | + { |
| 102 | + code: '{{link-to "Link text" "routeName" tagName="button"}}', |
| 103 | + output: null, |
| 104 | + errors: [{ message: 'tagName attribute on LinkTo is deprecated' }], |
| 105 | + }, |
| 106 | + ], |
| 107 | +}); |
0 commit comments