Skip to content

Commit 18f1677

Browse files
committed
Add a way to disable the warning for a specific link
1 parent 76ea80d commit 18f1677

File tree

1 file changed

+19
-25
lines changed

1 file changed

+19
-25
lines changed

scaladoc/src/dotty/tools/scaladoc/tasty/comments/Preparser.scala

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -134,32 +134,26 @@ object Preparser {
134134

135135
def processLink: Unit =
136136
if (!summon[DocContext].args.noLinkWarnings) then tags.get(SimpleTagKey("see")).get.foreach(link => {
137-
val newLink: String = link.replaceAll("\\[\\[|\\]\\]", "")
138-
val isValid = Try(new URL(newLink)).isSuccess
139-
isValid match {
140-
case true =>
141-
val url = new URL(newLink)
142-
url match {
143-
// We check if it's an internal link
144-
case s if s.getPath.contains("/docs/") =>
145-
if (newLink.contains("oracle")) then // exclude links containing "oracle"
146-
None
147-
else
148-
// We check if the internal link to the static documentation is valid
149-
val docPath = url.getPath.substring(url.getPath.indexOf("/docs/")).replaceFirst("/docs/", "docs/_docs/").replace(".html", ".md")
150-
println(docPath)
151-
val fileExists = Files.exists(Paths.get(docPath))
152-
if !fileExists then
153-
//Si le fichier n'existe pas, on vérifie si le fichier existe avec l'extension .md
154-
val newDocPath = docPath + ".md"
155-
if !Files.exists(Paths.get(newDocPath)) then
156-
report.warning(s"Link to $newLink will return a 404 not found")
157-
case _ => None
158-
}
159-
case false =>
160-
None
137+
val newLink = link.replaceAll("\\[\\[|\\]\\]", "")
138+
val newUrl = new URL(newLink)
139+
if(Try(newUrl).isSuccess) {
140+
if(newUrl.getPath.contains("/docs/")) {
141+
if (newLink.contains("oracle") || newLink.contains("excludeValidation")) then None
142+
else
143+
// We check if the internal link to the static documentation is valid
144+
val docPath = newUrl.getPath.substring(newUrl.getPath.indexOf("/docs/"))
145+
.replaceFirst("/docs/(docs/)?", "docs/_docs/")
146+
.replace(".html", ".md")
147+
println(docPath)
148+
val fileExists = Files.exists(Paths.get(docPath))
149+
if !fileExists then
150+
val newDocPath = docPath + ".md"
151+
if !Files.exists(Paths.get(newDocPath)) then report.warning(s"Link to $newLink will return a 404 not found")
161152
}
162-
})
153+
else None
154+
}
155+
else None
156+
})
163157

164158
val bodyTags: mutable.Map[TagKey, List[String]] =
165159
if tags.get(SimpleTagKey("see")).isDefined then

0 commit comments

Comments
 (0)