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

Commit

Permalink
Merge pull request #16 from cake-contrib/feature/gh-13
Browse files Browse the repository at this point in the history
(GH-13) Update to Cake.Issues 0.3.0
  • Loading branch information
pascalberger committed Jun 3, 2018
2 parents 663f9e4 + e5dc7ca commit 26b307a
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 22 deletions.
4 changes: 2 additions & 2 deletions src/Cake.Issues.EsLint.Tests/Cake.Issues.EsLint.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
<PackageReference Include="Cake.Core" Version="0.28.0" />
<PackageReference Include="Cake.Testing" Version="0.28.0" />
<PackageReference Include="Cake.Issues" Version="0.2.0" />
<PackageReference Include="Cake.Issues.Testing" Version="0.2.0" />
<PackageReference Include="Cake.Issues" Version="0.3.0-beta0003" />
<PackageReference Include="Cake.Issues.Testing" Version="0.3.0-beta0003" />
<PackageReference Include="Shouldly" Version="3.0.0" />
<PackageReference Include="StyleCop.Analyzers" Version="1.0.2" />
<PackageReference Include="xunit" Version="2.3.1" />
Expand Down
32 changes: 23 additions & 9 deletions src/Cake.Issues.EsLint.Tests/JsonFormatTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,71 +39,80 @@ public void Should_Read_Issue_Correct()
1,
"no-unused-vars",
"http://eslint.org/docs/rules/no-unused-vars",
2,
400,
"Error",
"'addOne' is defined but never used.");
CheckIssue(
issues[1],
@"src\Cake.Issues.EsLint.Tests\Testfiles\fullOfProblems.js",
2,
"use-isnan",
"http://eslint.org/docs/rules/use-isnan",
2,
400,
"Error",
"Use the isNaN function to compare with NaN.");
CheckIssue(
issues[2],
@"src\Cake.Issues.EsLint.Tests\Testfiles\fullOfProblems.js",
3,
"space-unary-ops",
"http://eslint.org/docs/rules/space-unary-ops",
2,
400,
"Error",
"Unexpected space before unary operator '++'.");
CheckIssue(
issues[3],
@"src\Cake.Issues.EsLint.Tests\Testfiles\fullOfProblems.js",
3,
"semi",
"http://eslint.org/docs/rules/semi",
1,
300,
"Warning",
"Missing semicolon.");
CheckIssue(
issues[4],
@"src\Cake.Issues.EsLint.Tests\Testfiles\fullOfProblems.js",
4,
"no-else-return",
"http://eslint.org/docs/rules/no-else-return",
1,
300,
"Warning",
"Unnecessary 'else' after 'return'.");
CheckIssue(
issues[5],
@"src\Cake.Issues.EsLint.Tests\Testfiles\fullOfProblems.js",
5,
"indent",
"http://eslint.org/docs/rules/indent",
1,
300,
"Warning",
"Expected indentation of 8 spaces but found 6.");
CheckIssue(
issues[6],
@"src\Cake.Issues.EsLint.Tests\Testfiles\fullOfProblems.js",
5,
"consistent-return",
"http://eslint.org/docs/rules/consistent-return",
2,
400,
"Error",
"Function 'addOne' expected a return value.");
CheckIssue(
issues[7],
@"src\Cake.Issues.EsLint.Tests\Testfiles\fullOfProblems.js",
5,
"semi",
"http://eslint.org/docs/rules/semi",
1,
300,
"Warning",
"Missing semicolon.");
CheckIssue(
issues[8],
@"src\Cake.Issues.EsLint.Tests\Testfiles\fullOfProblems.js",
7,
"no-extra-semi",
"http://eslint.org/docs/rules/no-extra-semi",
2,
400,
"Error",
"Unnecessary semicolon.");
}

Expand All @@ -114,8 +123,12 @@ public void Should_Read_Issue_Correct()
string rule,
string ruleUrl,
int priority,
string priorityName,
string message)
{
issue.ProviderType.ShouldBe("Cake.Issues.EsLint.EsLintIssuesProvider");
issue.ProviderName.ShouldBe("ESLint");

if (issue.AffectedFileRelativePath == null)
{
affectedFileRelativePath.ShouldBeNull();
Expand All @@ -139,6 +152,7 @@ public void Should_Read_Issue_Correct()
}

issue.Priority.ShouldBe(priority);
issue.PriorityName.ShouldBe(priorityName);
issue.Message.ShouldBe(message);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Cake.Issues.EsLint/Cake.Issues.EsLint.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

<ItemGroup>
<PackageReference Include="Cake.Core" Version="0.28.0" />
<PackageReference Include="Cake.Issues" Version="0.2.0" />
<PackageReference Include="Cake.Issues" Version="0.3.0-beta0003" />
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.6.0" />
<PackageReference Include="StyleCop.Analyzers" Version="1.0.2" />
<PackageReference Include="System.Runtime.Serialization.Json" Version="4.3.0" />
Expand Down
2 changes: 1 addition & 1 deletion src/Cake.Issues.EsLint/EsLintIssuesAliases.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static class EsLintIssuesAliases
{
context.NotNull(nameof(context));

return Issue<EsLintIssuesProvider>.GetProviderTypeName();
return typeof(EsLintIssuesProvider).FullName;
}

/// <summary>
Expand Down
7 changes: 5 additions & 2 deletions src/Cake.Issues.EsLint/EsLintIssuesProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/// <summary>
/// Provider for issues reported by ESLint.
/// </summary>
internal class EsLintIssuesProvider : IssueProvider
public class EsLintIssuesProvider : IssueProvider
{
private readonly EsLintIssuesSettings settings;

Expand All @@ -23,10 +23,13 @@ public EsLintIssuesProvider(ICakeLog log, EsLintIssuesSettings settings)
this.settings = settings;
}

/// <inheritdoc />
public override string ProviderName => "ESLint";

/// <inheritdoc />
protected override IEnumerable<IIssue> InternalReadIssues(IssueCommentFormat format)
{
return this.settings.Format.ReadIssues(this.Settings, this.settings);
return this.settings.Format.ReadIssues(this, this.Settings, this.settings);
}
}
}
2 changes: 2 additions & 0 deletions src/Cake.Issues.EsLint/ILogFileFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ public interface ILogFileFormat
/// <summary>
/// Gets all issues.
/// </summary>
/// <param name="issueProvider">Issue provider instance.</param>
/// <param name="repositorySettings">General settings to use.</param>
/// <param name="esLintSettings">Settings for issue provider to use.</param>
/// <returns>List of issues</returns>
IEnumerable<IIssue> ReadIssues(
EsLintIssuesProvider issueProvider,
RepositorySettings repositorySettings,
EsLintIssuesSettings esLintSettings);
}
Expand Down
38 changes: 31 additions & 7 deletions src/Cake.Issues.EsLint/JsonFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ public JsonFormat(ICakeLog log)

/// <inheritdoc />
public override IEnumerable<IIssue> ReadIssues(
EsLintIssuesProvider issueProvider,
RepositorySettings repositorySettings,
EsLintIssuesSettings esLintsettings)
{
issueProvider.NotNull(nameof(issueProvider));
repositorySettings.NotNull(nameof(repositorySettings));
esLintsettings.NotNull(nameof(esLintsettings));

Expand All @@ -44,13 +46,12 @@ public JsonFormat(ICakeLog log)
let
rule = message.ruleId
select
new Issue<EsLintIssuesProvider>(
GetRelativeFilePath(file.filePath, repositorySettings),
message.line,
message.message,
message.severity,
rule,
EsLintRuleUrlResolver.Instance.ResolveRuleUrl(rule));
IssueBuilder
.NewIssue(message.message, issueProvider)
.InFile(GetRelativeFilePath(file.filePath, repositorySettings), message.line)
.OfRule(rule, EsLintRuleUrlResolver.Instance.ResolveRuleUrl(rule))
.WithPriority(GetPriority(message.severity))
.Create();
}

return new List<IIssue>();
Expand All @@ -71,5 +72,28 @@ public JsonFormat(ICakeLog log)

return relativeFilePath;
}

/// <summary>
/// Converts the severity level to a priority.
/// </summary>
/// <param name="severity">Severity level as reported by ESLint.</param>
/// <returns>Priority</returns>
private static IssuePriority GetPriority(int severity)
{
switch (severity)
{
case 0:
return IssuePriority.Hint;

case 1:
return IssuePriority.Warning;

case 2:
return IssuePriority.Error;

default:
return IssuePriority.Undefined;
}
}
}
}
1 change: 1 addition & 0 deletions src/Cake.Issues.EsLint/LogFileFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ protected LogFileFormat(ICakeLog log)

/// <inheritdoc/>
public abstract IEnumerable<IIssue> ReadIssues(
EsLintIssuesProvider issueProvider,
RepositorySettings repositorySettings,
EsLintIssuesSettings esLintsettings);
}
Expand Down

0 comments on commit 26b307a

Please sign in to comment.