Examples

The following example will call markdownlint-cli to lint some markdown files and outputs the number of warnings.

To call markdownlint-cli from a Cake script you can use the Cake.Markdownlint addin.

#addin "Cake.Markdownlint" // (1)!
  1. In production code this dependency should be pinned to a specific version to make sure builds are deterministic and won't break due to updates.

    See Reproducible Builds for details.

To read issues from markdownlint-cli log files you need to import the core addin and the markdownlint support:

#addin nuget:?package=Cake.Issues&version=5.0.1
#addin nuget:?package=Cake.Issues.Markdownlint&version=5.0.1

We need some global variables:

var logPath = @"c:\build\markdownlint.log";
var repoRootFolder = MakeAbsolute(Directory("./"));

The following task will run markdownlint-cli and write a log file:

Task("Lint-Documentation").Does(() =>
{
    // Run markdownlint-cli.
    var settings =
        MarkdownlintNodeJsRunnerSettings.ForDirectory(repoRootPath.Combine("docs"));
    settings.OutputFile = logPath;
    settings.ThrowOnIssue = false;
    RunMarkdownlintNodeJs(settings);
});

Finally you can define a task where you call the core addin with the desired issue provider.

Task("Read-Issues")
    .IsDependentOn("Lint-Documentation")
    .Does(() =>
    {
        // Read Issues.
        var issues =
            ReadIssues(
                MarkdownlintIssuesFromFilePath(
                    logPath,
                    MarkdownlintCliLogFileFormat),
                repoRootPath);

        Information("{0} issues are found.", issues.Count());
    });