Skip to content

Commit

Permalink
Merge pull request #129 from scalameta/no-link-warnings
Browse files Browse the repository at this point in the history
Add option to disable link hygiene
  • Loading branch information
olafurpg authored Jan 1, 2019
2 parents f64b4b4 + 02264cd commit 2bd04bd
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 2 deletions.
2 changes: 2 additions & 0 deletions mdoc-docs/src/main/scala/mdoc/docs/SbtModifier.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ class SbtModifier extends StringModifier {
mdocIn,
mdocOut,
mdocVariables,
mdocExtraArguments,
mdocAutoDependency
)
val rows = keys.map { s =>
val tpe = s.key.manifest
.toString()
.replaceAllLiterally("java.lang.String", "String")
.replaceAllLiterally("scala.collection.immutable.", "")
.replaceAllLiterally("scala.collection.", "")
<tr>
<td><code>{s.key.toString}</code></td>
<td><code>{tpe}</code></td>
Expand Down
9 changes: 8 additions & 1 deletion mdoc-sbt/src/main/scala/mdoc/MdocPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ object MdocPlugin extends AutoPlugin {
"Output directory for mdoc generated markdown. " +
"Defaults to the target/mdoc directory of this project."
)
val mdocExtraArguments =
settingKey[Seq[String]](
"Additional command-line arguments to pass on every mdoc invocation. " +
"For example, add --no-link-hygiene to disable link hygiene."
)
val mdocAutoDependency =
settingKey[Boolean](
"If false, do not add mdoc as a library dependency this project. " +
Expand All @@ -49,10 +54,12 @@ object MdocPlugin extends AutoPlugin {
mdocOut := target.in(Compile).value / "mdoc",
mdocVariables := Map.empty,
mdocAutoDependency := true,
mdocExtraArguments := Nil,
mdoc := Def.inputTaskDyn {
val parsed = sbt.complete.DefaultParsers.spaceDelimited("<arg>").parsed
val args = mdocExtraArguments.value ++ parsed
Def.taskDyn {
runMain.in(Compile).toTask(s" mdoc.Main ${parsed.mkString(" ")}")
runMain.in(Compile).toTask(s" mdoc.Main ${args.mkString(" ")}")
}
}.evaluated,
libraryDependencies ++= {
Expand Down
3 changes: 3 additions & 0 deletions mdoc/src/main/scala/mdoc/MainSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ final class MainSettings private (
def withCheck(check: Boolean): MainSettings = {
copy(settings.copy(check = check))
}
def withNoLinkHygiene(noLinkHygiene: Boolean): MainSettings = {
copy(settings.copy(noLinkHygiene = noLinkHygiene))
}
def withReportRelativePaths(reportRelativePaths: Boolean): MainSettings = {
copy(settings.copy(reportRelativePaths = reportRelativePaths))
}
Expand Down
2 changes: 1 addition & 1 deletion mdoc/src/main/scala/mdoc/internal/cli/MainOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ final class MainOps(
}

def lint(): Unit = {
if (settings.out.isDirectory) {
if (settings.out.isDirectory && !settings.noLinkHygiene) {
val docs = DocumentLinks.fromGeneratedSite(settings, reporter)
LinkHygiene.lint(docs, reporter, settings.verbose)
}
Expand Down
2 changes: 2 additions & 0 deletions mdoc/src/main/scala/mdoc/internal/cli/Settings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ case class Settings(
)
@ExtraName("test")
check: Boolean = false,
@Description("Disable link hygiene analysis so that no warnings are reported for dead links.")
noLinkHygiene: Boolean = false,
@Description("Include additional diagnostics for debugging potential problems.")
verbose: Boolean = false,
@Description(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ abstract class BaseMarkdownSuite extends org.scalatest.FunSuite with DiffAsserti
print(colorOut)
val stdout = fansi.Str(colorOut).plainText
assert(!reporter.hasErrors, stdout)
assert(!reporter.hasWarnings, stdout)
assertNoDiffOrPrintExpected(obtained, expected)
}
}
Expand Down
25 changes: 25 additions & 0 deletions tests/unit/src/test/scala/tests/markdown/NoLinkWarningSuite.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package tests.markdown

import tests.cli.BaseCliSuite

class NoLinkWarningSuite extends BaseCliSuite {
val original =
"""/readme.md
|# Header
|
|[Head](#head)
""".stripMargin

checkCli(
"nowarn",
original,
original,
extraArgs = Array(
"--no-link-hygiene"
),
onStdout = { out =>
assert(!out.contains("warning"))
}
)

}

0 comments on commit 2bd04bd

Please sign in to comment.