You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/rules/jsx-no-target-blank.md
+33-9Lines changed: 33 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -20,37 +20,61 @@ This rule aims to prevent user generated links from creating security vulnerabil
20
20
21
21
* enabled: for enabling the rule. 0=off, 1=warn, 2=error. Defaults to 0.
22
22
* enforce: optional string, 'always' or 'never'
23
+
* Link components can be something other than an `<a>`, see [shared settings](https://github.com/yannickcr/eslint-plugin-react/blob/master/README.md#configuration) for `linkComponents` configuration)
24
+
25
+
### `enforceDynamicLinks`
26
+
27
+
#### always
23
28
24
-
### always (default)
25
29
`{"enforceDynamicLinks": "always"}` enforces the rule if the href is a dynamic link (default)
26
30
27
31
When {"enforceDynamicLinks": "always"} is set, the following patterns are considered errors:
28
32
29
33
```jsx
30
34
var Hello =<a target='_blank' href="http://example.com/"></a>
31
-
var Hello =<a target='_blank' href={dynamicLink}></a>
35
+
var Hello =<a target='_blank' href={dynamicLink}></a>
32
36
```
33
37
34
38
The following patterns are **not** considered errors:
35
39
36
40
```jsx
37
-
var Hello =<p target='_blank'></p>
38
-
var Hello =<a target='_blank' rel='noopener noreferrer' href="http://example.com"></a>
39
-
var Hello =<a target='_blank' href="relative/path/in/the/host"></a>
40
-
var Hello =<a target='_blank' href="/absolute/path/in/the/host"></a>
41
+
var Hello =<p target="_blank"></p>
42
+
var Hello =<a target="_blank" rel="noopener noreferrer" href="http://example.com"></a>
43
+
var Hello =<a target="_blank" href="relative/path/in/the/host"></a>
44
+
var Hello =<a target="_blank" href="/absolute/path/in/the/host"></a>
41
45
var Hello =<a></a>
42
46
```
43
47
44
-
### never
48
+
####never
45
49
46
50
`{"enforceDynamicLinks": "never"}` does not enforce the rule if the href is a dynamic link
47
51
48
52
When {"enforceDynamicLinks": "never"} is set, the following patterns are **not** considered errors:
49
53
50
54
```jsx
51
-
var Hello =<a target='_blank' href={ dynamicLink }></a>
55
+
var Hello =<a target='_blank' href={dynamicLink}></a>
56
+
```
57
+
58
+
### Link components
59
+
60
+
Link components can be something other than an `<a>`, see [shared settings](https://github.com/yannickcr/eslint-plugin-react/blob/master/README.md#configuration) for `linkComponents` configuration)
61
+
62
+
The following patterns are considered errors:
63
+
64
+
```jsx
65
+
var Hello =<Link target="_blank" to="http://example.com/"></Link>
66
+
var Hello =<Link target="_blank" to={dynamicLink}></Link>
67
+
```
68
+
69
+
The following patterns are **not** considered errors:
70
+
71
+
```jsx
72
+
var Hello =<Link target="_blank" rel="noopener noreferrer" to="http://example.com"></Link>
73
+
var Hello =<Link target="_blank" to="relative/path/in/the/host"></Link>
74
+
var Hello =<Link target="_blank" to="/absolute/path/in/the/host"></Link>
75
+
var Hello =<Link />
52
76
```
53
77
54
78
## When Not To Use It
55
79
56
-
If you do not have any external links, you can disable this rule
80
+
If you do not have any external links, you can disable this rule
0 commit comments