|
| 1 | +const rule = require('../a11y-link-in-text-block') |
| 2 | +const {RuleTester} = require('eslint') |
| 3 | + |
| 4 | +const ruleTester = new RuleTester({ |
| 5 | + parserOptions: { |
| 6 | + ecmaVersion: 'latest', |
| 7 | + sourceType: 'module', |
| 8 | + ecmaFeatures: { |
| 9 | + jsx: true, |
| 10 | + }, |
| 11 | + }, |
| 12 | +}) |
| 13 | + |
| 14 | +ruleTester.run('a11y-link-in-text-block', rule, { |
| 15 | + valid: [ |
| 16 | + `import {Link} from '@primer/react'; |
| 17 | + <Box> |
| 18 | + |
| 19 | + <Link href="something"> |
| 20 | + Blah blah |
| 21 | + </Link>{' '} |
| 22 | + . |
| 23 | + </Box> |
| 24 | + `, |
| 25 | + `import {Text, Link} from '@primer/react'; |
| 26 | + <Something> |
| 27 | + <Link href='blah'> |
| 28 | + blah |
| 29 | + </Link> |
| 30 | + </Something> |
| 31 | + `, |
| 32 | + `import {Link} from '@primer/react'; |
| 33 | + <p>bla blah <Link inline={true}>Link level 1</Link></p>; |
| 34 | + `, |
| 35 | + `import {Link} from '@primer/react'; |
| 36 | + <p>bla blah<Link inline>Link level 1</Link></p>; |
| 37 | + `, |
| 38 | + `import {Link} from '@primer/react'; |
| 39 | + <><span>something</span><Link inline={true}>Link level 1</Link></>; |
| 40 | + `, |
| 41 | + `import {Link} from '@primer/react'; |
| 42 | + <Link>Link level 1</Link>; |
| 43 | +`, |
| 44 | + `import {Heading, Link} from '@primer/react'; |
| 45 | + <Heading> |
| 46 | + <Link>Link level 1</Link> |
| 47 | + hello |
| 48 | + </Heading> |
| 49 | +`, |
| 50 | + `import {Heading, Link} from '@primer/react'; |
| 51 | + <Heading as="h2"> |
| 52 | + <Link href={somePath}> |
| 53 | + Breadcrumb |
| 54 | + </Link> |
| 55 | + Create a thing |
| 56 | + </Heading> |
| 57 | +`, |
| 58 | + `import {Link} from '@primer/react'; |
| 59 | + <div> |
| 60 | + <h2> |
| 61 | + <Link href={somePath}> |
| 62 | + Breadcrumb |
| 63 | + </Link> |
| 64 | + </h2> |
| 65 | + Create a thing |
| 66 | + </div> |
| 67 | +`, |
| 68 | + `import {Link} from '@primer/react'; |
| 69 | + <div> |
| 70 | + <Link href={somePath}> |
| 71 | + <GitHubAvatar />{owner} |
| 72 | + </Link>{' '} |
| 73 | + last edited{' '} |
| 74 | + </div> |
| 75 | +`, |
| 76 | + `import {Link} from '@primer/react'; |
| 77 | + <span> |
| 78 | + by |
| 79 | + <Link href="something" sx={{p: 2, fontWeight: 'bold'}}> |
| 80 | + Blah blah |
| 81 | + </Link> |
| 82 | + </span> |
| 83 | +`, |
| 84 | + `import {Link} from '@primer/react'; |
| 85 | + <span> |
| 86 | + by |
| 87 | + <Link href="something" sx={{fontWeight: 'bold'}}> |
| 88 | + Blah blah |
| 89 | + </Link> |
| 90 | + </span> |
| 91 | +`, |
| 92 | + `import {Link} from '@primer/react'; |
| 93 | + <span> |
| 94 | + by |
| 95 | + <Link href="something" sx={{fontFamily: 'mono'}}> |
| 96 | + Blah blah |
| 97 | + </Link> |
| 98 | + </span> |
| 99 | + `, |
| 100 | + `import {Link} from '@primer/react'; |
| 101 | + <Box> |
| 102 | +
|
| 103 | + <Link href="something"> |
| 104 | + Blah blah |
| 105 | + </Link>{' '} |
| 106 | + . |
| 107 | + </Box> |
| 108 | +`, |
| 109 | + `import {Link} from '@primer/react'; |
| 110 | +<Heading sx={{fontSize: 1, mb: 3}} as="h3"> |
| 111 | + In addition,{' '} |
| 112 | + <Link href="https://github.com/pricing" target="_blank"> |
| 113 | + GitHub Team |
| 114 | + </Link>{' '} |
| 115 | + includes: |
| 116 | + </Heading> |
| 117 | +`, |
| 118 | + ], |
| 119 | + invalid: [ |
| 120 | + { |
| 121 | + code: `import {Link} from '@primer/react'; |
| 122 | + <p>bla blah<Link>Link level 1</Link></p> |
| 123 | + `, |
| 124 | + errors: [{messageId: 'linkInTextBlock'}], |
| 125 | + }, |
| 126 | + { |
| 127 | + code: `import {Link} from '@primer/react'; |
| 128 | + <p><Link>Link level 1</Link> something something</p> |
| 129 | + `, |
| 130 | + errors: [{messageId: 'linkInTextBlock'}], |
| 131 | + }, |
| 132 | + { |
| 133 | + code: `import {Link} from '@primer/react'; |
| 134 | + <p>bla blah<Link inline={false}>Link level 1</Link></p> |
| 135 | + `, |
| 136 | + errors: [{messageId: 'linkInTextBlock'}], |
| 137 | + }, |
| 138 | + { |
| 139 | + code: `import {Link} from '@primer/react'; |
| 140 | + <Box>Something something{' '} |
| 141 | + <Link>Link level 1</Link> |
| 142 | + </Box> |
| 143 | + `, |
| 144 | + errors: [{messageId: 'linkInTextBlock'}], |
| 145 | + }, |
| 146 | + { |
| 147 | + code: `import {Link} from '@primer/react'; |
| 148 | + <>blah blah blah{' '} |
| 149 | + <Link>Link level 1</Link></>; |
| 150 | + `, |
| 151 | + errors: [{messageId: 'linkInTextBlock'}], |
| 152 | + }, |
| 153 | + { |
| 154 | + code: `import {Link} from '@primer/react'; |
| 155 | + <>blah blah blah{' '} |
| 156 | + <Link underline>Link level 1</Link></>; |
| 157 | + `, |
| 158 | + errors: [{messageId: 'linkInTextBlock'}], |
| 159 | + }, |
| 160 | + ], |
| 161 | +}) |
0 commit comments