Skip to content

Commit eae31a0

Browse files
committed
add example of complete react/jsx-no-target-blank rule
1 parent 60b5642 commit eae31a0

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

docs/rules/jsx-no-target-blank.md

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,35 +15,43 @@ This rule aims to prevent user generated links from creating security vulnerabil
1515

1616
There are two main options for the rule:
1717

18-
* `{"enforceDynamicLinks": "always"}` enforces the rule if the href is a dynamic link (default)
19-
* `{"enforceDynamicLinks": "never"}` does not enforce the rule if the href is a dynamic link
18+
- `{"enforceDynamicLinks": "always"}` enforces the rule if the href is a dynamic link (default)
19+
- `{"enforceDynamicLinks": "never"}` does not enforce the rule if the href is a dynamic link
2020

21+
```json
22+
"react/jsx-no-target-blank": [<enabled>, { enforceDynamicLinks: <enforce> }]
23+
```
24+
25+
- enabled: for enabling the rule. 0=off, 1=warn, 2=error. Defaults to 0.
26+
- enforce: optional string, defaults to "always"
2127

2228
### always (default)
2329

2430
When {"enforceDynamicLinks": "always"} is set, the following patterns are considered errors:
2531

2632
```jsx
27-
var Hello = <a target='_blank' href="http://example.com/"></a>
28-
var Hello = <a target='_blank' href={ dynamicLink }></a>
33+
var Hello = <a target="_blank" href="http://example.com/" />;
34+
var Hello = <a target="_blank" href={dynamicLink} />;
2935
```
3036

3137
The following patterns are **not** considered errors:
3238

3339
```jsx
34-
var Hello = <p target='_blank'></p>
35-
var Hello = <a target='_blank' rel='noopener noreferrer' href="http://example.com"></a>
36-
var Hello = <a target='_blank' href="relative/path/in/the/host"></a>
37-
var Hello = <a target='_blank' href="/absolute/path/in/the/host"></a>
38-
var Hello = <a></a>
40+
var Hello = <p target="_blank" />;
41+
var Hello = (
42+
<a target="_blank" rel="noopener noreferrer" href="http://example.com" />
43+
);
44+
var Hello = <a target="_blank" href="relative/path/in/the/host" />;
45+
var Hello = <a target="_blank" href="/absolute/path/in/the/host" />;
46+
var Hello = <a />;
3947
```
4048

4149
### never
4250

4351
When {"enforceDynamicLinks": "never"} is set, the following patterns are **not** considered errors:
4452

4553
```jsx
46-
var Hello = <a target='_blank' href={ dynamicLink }></a>
54+
var Hello = <a target="_blank" href={dynamicLink} />;
4755
```
4856

4957
## When Not To Use It

0 commit comments

Comments
 (0)