Skip to content
This repository has been archived by the owner on Dec 26, 2023. It is now read-only.

Commit

Permalink
Merge branch 'release/1.1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalberger committed Sep 1, 2021
2 parents 38130a1 + 16ec461 commit 88b3a0c
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 14 deletions.
2 changes: 1 addition & 1 deletion nuspec/nuget/Cake.Issues.Markdownlint.nuspec
Expand Up @@ -24,7 +24,7 @@ See the Project Site for an overview of the whole ecosystem of addins for workin
<repository type="git" url="https://github.com/cake-contrib/Cake.Issues.Markdownlint.git"/>
<copyright>Copyright © BBT Software AG and contributors</copyright>
<tags>cake cake-addin cake-issues cake-issueprovider linting markdown markdownlint</tags>
<releaseNotes>https://github.com/cake-contrib/Cake.Issues.Markdownlint/releases/tag/1.1.0</releaseNotes>
<releaseNotes>https://github.com/cake-contrib/Cake.Issues.Markdownlint/releases/tag/1.1.1</releaseNotes>
</metadata>
<files>
<file src="..\..\..\..\nuspec\nuget\icon.png" target="" />
Expand Down
Expand Up @@ -17,32 +17,38 @@
<CodeAnalysisRuleSet>..\Cake.Issues.Markdownlint.Tests.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Cake.Issues.Markdownlint\Cake.Issues.Markdownlint.csproj" />
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
<ItemGroup>
<None Remove="Testfiles\MarkdownlintCliJsonLogFileFormat\AbsoluteFilePath.json" />
<None Remove="Testfiles\MarkdownlintCliJsonLogFileFormat\empty.json" />
<None Remove="Testfiles\MarkdownlintCliJsonLogFileFormat\MD013.json" />
<None Remove="Testfiles\MarkdownlintCliJsonLogFileFormat\MD025.json" />
<None Remove="Testfiles\MarkdownlintCliJsonLogFileFormat\MD034.json" />
<None Remove="Testfiles\MarkdownlintCliLogFileFormat\empty.log" />
<None Remove="Testfiles\MarkdownlintCliLogFileFormat\markdownlint-cli-0.8.1.log" />
<None Remove="Testfiles\MarkdownlintCliLogFileFormat\markdownlint-cli-0.10.0.log" />
<None Remove="Testfiles\MarkdownlintCliLogFileFormat\markdownlint-cli-0.19.0.log" />
<None Remove="Testfiles\MarkdownlintCliLogFileFormat\markdownlint-cli-0.22.0.log" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Cake.Issues.Markdownlint\Cake.Issues.Markdownlint.csproj" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Testfiles\MarkdownlintCliJsonLogFileFormat\AbsoluteFilePath.json" />
<EmbeddedResource Include="Testfiles\MarkdownlintCliJsonLogFileFormat\empty.json" />
<EmbeddedResource Include="Testfiles\MarkdownlintCliJsonLogFileFormat\MD013.json" />
<EmbeddedResource Include="Testfiles\MarkdownlintCliJsonLogFileFormat\MD025.json" />
<EmbeddedResource Include="Testfiles\MarkdownlintCliJsonLogFileFormat\MD034.json" />
<EmbeddedResource Include="Testfiles\MarkdownlintCliLogFileFormat\empty.log" />
<EmbeddedResource Include="Testfiles\MarkdownlintCliLogFileFormat\markdownlint-cli-0.8.1.log" />
<EmbeddedResource Include="Testfiles\MarkdownlintCliLogFileFormat\markdownlint-cli-0.10.0.log" />
<EmbeddedResource Include="Testfiles\MarkdownlintCliLogFileFormat\markdownlint-cli-0.19.0.log" />
<EmbeddedResource Include="Testfiles\MarkdownlintCliLogFileFormat\markdownlint-cli-0.22.0.log" />
<EmbeddedResource Include="Testfiles\MarkdownlintV1LogFileFormat\markdownlint.json" />
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<EmbeddedResource Include="Testfiles\MarkdownlintCliLogFileFormat\markdownlint-cli-0.8.1.log" />
<EmbeddedResource Include="Testfiles\MarkdownlintCliLogFileFormat\markdownlint-cli-0.10.0.log" />
<EmbeddedResource Include="Testfiles\MarkdownlintCliLogFileFormat\markdownlint-cli-0.19.0.log" />
<EmbeddedResource Include="Testfiles\MarkdownlintCliLogFileFormat\empty.log" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Cake.Issues">
Expand Down
Expand Up @@ -106,6 +106,32 @@ public void Should_Read_Issue_MD034_Correct()
.OfRule("MD034", new Uri("https://github.com/DavidAnson/markdownlint/blob/v0.23.1/doc/Rules.md#md034"))
.WithPriority(IssuePriority.Warning));
}

[Fact]
public void Should_Read_Issue_With_Absolute_Path_Correct()
{
// Given
var fixture =
new MarkdownlintIssuesProviderFixture<MarkdownlintCliJsonLogFileFormat>("AbsoluteFilePath.json")
{
ReadIssuesSettings = new ReadIssuesSettings("/markdown"),
};

// When
var issues = fixture.ReadIssues().ToList();

// Then
issues.Count.ShouldBe(1);
IssueChecker.Check(
issues[0],
IssueBuilder.NewIssue(
"Headings should be surrounded by blank lines: Expected: 1; Actual: 0; Below",
"Cake.Issues.Markdownlint.MarkdownlintIssuesProvider",
"markdownlint")
.InFile("docs/input/index.md", 4)
.OfRule("MD022", new Uri("https://github.com/DavidAnson/markdownlint/blob/v0.23.1/doc/Rules.md#md022"))
.WithPriority(IssuePriority.Warning));
}
}
}
}
@@ -0,0 +1,20 @@
[
{
"fileName": "/markdown/docs/input/index.md",
"lineNumber": 4,
"ruleNames": [
"MD022",
"blanks-around-headings",
"blanks-around-headers"
],
"ruleDescription": "Headings should be surrounded by blank lines",
"ruleInformation": "https://github.com/DavidAnson/markdownlint/blob/v0.23.1/doc/Rules.md#md022",
"errorDetail": "Expected: 1; Actual: 0; Below",
"errorContext": "# Foo",
"errorRange": null,
"fixInfo": {
"lineNumber": 5,
"insertText": "\n"
}
}
]
Expand Up @@ -7,6 +7,7 @@
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
using Cake.Core.Diagnostics;
using Cake.Core.IO;

/// <summary>
/// Logfile format as written by markdownlint-cli with <c>--json</c> parameter.
Expand Down Expand Up @@ -49,18 +50,20 @@ public MarkdownlintCliJsonLogFileFormat(ICakeLog log)
return new List<IIssue>();
}

return logFileEntries.Select(x => GetIssue(x, issueProvider));
return logFileEntries.Select(x => GetIssue(x, issueProvider, repositorySettings));
}

/// <summary>
/// Returns the issue for a message from the log file.
/// </summary>
/// <param name="logFileEntry">Issue reported by markdownlint.</param>
/// <param name="issueProvider">Issue provider instance.</param>
/// <param name="repositorySettings">Repository settings.</param>
/// <returns>Issue instance.</returns>
private static IIssue GetIssue(
LogFileEntry logFileEntry,
MarkdownlintIssuesProvider issueProvider)
MarkdownlintIssuesProvider issueProvider,
IRepositorySettings repositorySettings)
{
var message = logFileEntry.ruleDescription;

Expand All @@ -73,7 +76,7 @@ public MarkdownlintCliJsonLogFileFormat(ICakeLog log)
IssueBuilder
.NewIssue(message, issueProvider)
.InFile(
logFileEntry.fileName,
GetFilePath(logFileEntry.fileName, repositorySettings),
logFileEntry.lineNumber,
logFileEntry.errorRange != null ? logFileEntry.lineNumber : null,
logFileEntry.errorRange != null ? logFileEntry.errorRange[0] : null,
Expand All @@ -83,6 +86,27 @@ public MarkdownlintCliJsonLogFileFormat(ICakeLog log)
.Create();
}

/// <summary>
/// Returns the file path of the issue.
/// </summary>
/// <param name="filePath">File path as reported by markdownlint.</param>
/// <param name="repositorySettings">Repository settings.</param>
/// <returns>File path absolute to repository root.</returns>
private static string GetFilePath(
string filePath,
IRepositorySettings repositorySettings)
{
var directoryPath = new DirectoryPath(filePath);

if (directoryPath.IsRelative)
{
return filePath;
}

// Absolute paths need to be made relative to repository root.
return repositorySettings.RepositoryRoot.GetRelativePath(directoryPath).FullPath;
}

#pragma warning disable SA1307 // Accessible fields must begin with upper-case letter
#pragma warning disable SA1401 // Fields must be private
#pragma warning disable CS0649 // Field 'field' is never assigned to, and will always have its default value 'value'
Expand Down

0 comments on commit 88b3a0c

Please sign in to comment.