Skip to content

Commit

Permalink
Fix some unnecessary reports of DT link replacement
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh-Cena committed Aug 10, 2024
1 parent 40c0a64 commit c02c077
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
9 changes: 9 additions & 0 deletions docs/warning-info.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,15 @@ In this case, you can replace the link with:
This property reflects the [`x`](/en-US/docs/Web/HTML/Attribute/x) attribute.
```

Currently, this check only reports if the link to be replaced is a subpage of the original link. This ensures that if the DT links to a generic page like:

```md
- [`x`](/en-US/docs/Web/HTML/Attributes_in_general)
- Description of `x`.
```

We don't lose information by replacing it.

## Self link

This rule reports links pointing to the page it's already on, including links that contain an anchor but also the full path. Some of them are generated by macros.
Expand Down
5 changes: 3 additions & 2 deletions src/server/create-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,8 @@ graph.forEachNode((node) => {
const targetDtLink = dtIdToLink
.get(url.pathname)
?.get(url.hash.slice(1));
if (targetDtLink) {
// Only report if the link to be replaced with is a subpage
if (targetDtLink && targetDtLink.href.startsWith(url.pathname)) {
report(
node,
"Replace DT link with real target",
Expand All @@ -326,7 +327,7 @@ graph.forEachNode((node) => {
}
} else {
const targetDtLink = dtIdToLink.get(node.id)?.get(linkTarget.slice(1));
if (targetDtLink) {
if (targetDtLink && targetDtLink.href.startsWith(node.id)) {
report(
node,
"Replace DT link with real target",
Expand Down

0 comments on commit c02c077

Please sign in to comment.