Skip to content

Commit bb777ca

Browse files
authored
docs: New example for avoiding nested links in TSX (#666)
1 parent ba4d2ff commit bb777ca

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

website/catalog/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,6 @@ Feel free to join our [Discord](https://discord.gg/4YZjf6htSQ) channel and ask @
4747
* [Unnecessary React Hook](/catalog/tsx/#avoid-unnecessary-react-hook)
4848
* [Unnecessary `useState` Type](/catalog/tsx/#unnecessary-usestate-type)
4949
* [Reverse React Compiler™](/catalog/tsx/#reverse-react-compilertm)
50+
* [Avoid nested links](/catalog/tsx/#avoid-nested-links)
5051
* [YAML](/catalog/yaml/)
5152
* [Find key/value and show message](/catalog/yaml/#find-key-value-and-show-message-using-those-key-vals)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
## Avoid nested links
2+
* [Playground Link](https://ast-grep.github.io/playground.html#eyJtb2RlIjoiQ29uZmlnIiwibGFuZyI6InRzeCIsInF1ZXJ5IjoiaWYgKCRBKSB7ICQkJEIgfSIsInJld3JpdGUiOiJpZiAoISgkQSkpIHtcbiAgICByZXR1cm47XG59XG4kJCRCIiwic3RyaWN0bmVzcyI6InNtYXJ0Iiwic2VsZWN0b3IiOiIiLCJjb25maWciOiJpZDogbm8tbmVzdGVkLWxpbmtzXG5sYW5ndWFnZTogdHN4XG5zZXZlcml0eTogZXJyb3JcbnJ1bGU6XG4gIHBhdHRlcm46IDxhICQkJD4kJCRBPC9hPlxuICBoYXM6XG4gICAgcGF0dGVybjogPGEgJCQkPiQkJDwvYT5cbiAgICBzdG9wQnk6IGVuZCIsInNvdXJjZSI6ImZ1bmN0aW9uIENvbXBvbmVudCgpIHtcbiAgcmV0dXJuIDxhIGhyZWY9Jy9kZXN0aW5hdGlvbic+XG4gICAgPGEgaHJlZj0nL2Fub3RoZXJkZXN0aW5hdGlvbic+TmVzdGVkIGxpbmshPC9hPlxuICA8L2E+O1xufVxuZnVuY3Rpb24gT2theUNvbXBvbmVudCgpIHtcbiAgcmV0dXJuIDxhIGhyZWY9Jy9kZXN0aW5hdGlvbic+XG4gICAgSSBhbSBqdXN0IGEgbGluay5cbiAgPC9hPjtcbn0ifQ==)
3+
4+
### Description
5+
6+
React will produce a warning message if you nest a link element inside of another link element. This rule will catch this mistake!
7+
8+
9+
### YAML
10+
11+
```yaml
12+
id: no-nested-links
13+
language: tsx
14+
severity: error
15+
rule:
16+
pattern: <a $$$>$$$A</a>
17+
has:
18+
pattern: <a $$$>$$$</a>
19+
stopBy: end
20+
```
21+
22+
### Example
23+
24+
<!-- highlight matched code in curly-brace {lineNum} -->
25+
```tsx {1-5}
26+
function Component() {
27+
return <a href='/destination'>
28+
<a href='/anotherdestination'>Nested link!</a>
29+
</a>;
30+
}
31+
function OkayComponent() {
32+
return <a href='/destination'>
33+
I am just a link.
34+
</a>;
35+
}
36+
```
37+
38+
### Contributed by
39+
[Tom MacWright](https://macwright.com/)

website/catalog/tsx/index.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ In order to reduce rule duplication, you can use the [`languageGlobs`](/referenc
1313
<!--@include: ./avoid-jsx-short-circuit.md-->
1414
<!--@include: ./rewrite-mobx-component.md-->
1515
<!--@include: ./unnecessary-react-hook.md-->
16-
<!--@include: ./reverse-react-compiler.md-->
16+
<!--@include: ./reverse-react-compiler.md-->
17+
<!--@include: ./avoid-nested-links.md-->

0 commit comments

Comments
 (0)