-
-
Notifications
You must be signed in to change notification settings - Fork 9.9k
Expand file tree
/
Copy pathno-html-links.test.ts
More file actions
103 lines (99 loc) · 2.69 KB
/
no-html-links.test.ts
File metadata and controls
103 lines (99 loc) · 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import rule from '../no-html-links';
import {RuleTester} from './testUtils';
const errorsJSX = [{messageId: 'link'}] as const;
const ruleTester = new RuleTester({
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaFeatures: {
jsx: true,
},
},
});
ruleTester.run('prefer-docusaurus-link', rule, {
valid: [
{
code: '<Link to="/test">test</Link>',
},
{
code: '<Link to="https://x.com/docusaurus">X</Link>',
},
{
code: '<a href="https://x.com/docusaurus">X</a>',
options: [{ignoreFullyResolved: true}],
},
{
code: '<a href={`https://x.com/docusaurus`}>X</a>',
options: [{ignoreFullyResolved: true}],
},
{
code: '<a href="mailto:viktor@malmedal.dev">Contact</a> ',
options: [{ignoreFullyResolved: true}],
},
{
code: '<a href="tel:123456789">Call</a>',
options: [{ignoreFullyResolved: true}],
},
{
// eslint-disable-next-line no-template-curly-in-string
code: '<a href={`https://x.com/${"docu" + "saurus"} ${"rex"}`}>Twitter</a>',
options: [{ignoreFullyResolved: true}],
},
{
code: '<a href={"https://x.com/" + "docusaurus"}>X</a>',
options: [{ignoreFullyResolved: true}],
},
],
invalid: [
{
code: '<a href="/test">test</a>',
errors: errorsJSX,
},
{
code: '<a href="https://x.com/docusaurus" target="_blank">test</a>',
errors: errorsJSX,
},
{
code: '<a href="https://x.com/docusaurus" target="_blank" rel="noopener noreferrer">test</a>',
errors: errorsJSX,
},
{
code: '<a href="mailto:viktor@malmedal.dev">Contact</a> ',
errors: errorsJSX,
},
{
code: '<a href="tel:123456789">Call</a>',
errors: errorsJSX,
},
{
code: '<a href={``}>Twitter</a>',
errors: errorsJSX,
},
{
code: '<a href={`https://www.twitter.com/docusaurus`}>Twitter</a>',
errors: errorsJSX,
},
{
code: '<a href="www.twitter.com/docusaurus">Twitter</a>',
options: [{ignoreFullyResolved: true}],
errors: errorsJSX,
},
{
// Dynamic template literals that can't be resolved should be reported
code: '<a href={`https://github.com/${repo}`}>GitHub</a>',
options: [{ignoreFullyResolved: true}],
errors: errorsJSX,
},
{
// Partially resolved but not fully (path starts with /)
code: '<a href={`/${path}`}>Internal</a>',
options: [{ignoreFullyResolved: true}],
errors: errorsJSX,
},
],
});