Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check-link-hygiene bug fix and sbt integration tweak #704

Merged
merged 5 commits into from
Sep 27, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mdoc-sbt/src/main/scala/mdoc/MdocPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ object MdocPlugin extends AutoPlugin {
parsed
).flatten.mkString(" ")
Def.taskDyn {
runMain.in(Compile).toTask(s" mdoc.Main $args")
runMain.in(Compile).toTask(s" mdoc.SbtMain $args")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you be able to add a scripted test to check the regression?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, let me look into it

is the name SbtMain fine for you?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, whichever is fine. Maybe it's better since it indicates that we are talking about main that should be used for a build tool.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add scaladoc on top of it + a scripted test that checks --check and --check-link-hygiene do not exit but still fail sbt task

}
}.evaluated,
dependencyOverrides ++= List(
Expand Down
13 changes: 10 additions & 3 deletions mdoc/src/main/scala/mdoc/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,21 @@ import mdoc.internal.cli.Settings
import mdoc.internal.io.ConsoleReporter
import mdoc.internal.markdown.Markdown

object Main {

object Main extends MainProcess {
def main(args: Array[String]): Unit = {
val code = process(args, System.out, PathIO.workingDirectory.toNIO)
if (code != 0) sys.exit(code)
}
}

object SbtMain extends MainProcess {
def main(args: Array[String]): Unit = {
val code = process(args, System.out, PathIO.workingDirectory.toNIO)
if (code != 0) sys.error("mdoc failed")
}
}

trait MainProcess {
def process(args: Array[String], out: PrintStream, cwd: Path): Int = {
process(args, new ConsoleReporter(out), cwd)
}
Expand All @@ -28,5 +36,4 @@ object Main {
def process(settings: MainSettings): Int = {
MainOps.process(Configured.ok(settings.settings), settings.reporter)
}

}
3 changes: 2 additions & 1 deletion mdoc/src/main/scala/mdoc/internal/cli/MainOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ final class MainOps(
val docs = DocumentLinks.fromGeneratedSite(settings)
val results = LinkHygiene.lint(docs, settings.verbose)
LinkHygiene.report(settings.checkLinkHygiene, results, reporter)
if (settings.checkLinkHygiene) {

if (settings.checkLinkHygiene && results.nonEmpty) {
acc.merge(Exit.error)
} else {
acc.merge(Exit.success)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,19 @@ class CheckLinkHygieneSuite extends BaseCliSuite {
expectedExitCode = 1
)

val valid =
"""/readme.md
|# Valid
""".stripMargin

checkCli(
"pass",
valid,
valid,
extraArgs = Array(
"--check-link-hygiene"
),
expectedExitCode = 0
)

}