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

Add test case for parsing files generated by ESLint #517

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions src/Cake.Issues.Sarif.Tests/Cake.Issues.Sarif.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,14 @@
<CodeAnalysisRuleSet>..\Cake.Issues.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>

<ItemGroup>
<None Remove="Testfiles\eslint.sarif" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="Testfiles\cake.issues.reporting.sarif.sarif" />
<EmbeddedResource Include="Testfiles\comprehensive.sarif" />
<EmbeddedResource Include="Testfiles\eslint.sarif" />
<EmbeddedResource Include="Testfiles\minimal.sarif" />
<EmbeddedResource Include="Testfiles\recommended-with-source.sarif" />
<EmbeddedResource Include="Testfiles\recommended-without-source.sarif" />
Expand Down
24 changes: 24 additions & 0 deletions src/Cake.Issues.Sarif.Tests/SarifIssuesProviderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,30 @@ public void Should_Read_Issue_Correct_For_File_Generated_By_CakeIssuesReportingS
.WithPriority(IssuePriority.Warning)
.Create());
}

[Fact]
public void Should_Read_Issue_Correct_For_File_Generated_By_EsLint()
{
// Given
var fixture = new SarifIssuesProviderFixture("eslint.sarif");

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

// Then
issues.Count.ShouldBe(1);
var issue = issues.Single();
IssueChecker.Check(
issue,
IssueBuilder.NewIssue(
"'x' is assigned a value but never used.",
"Cake.Issues.Sarif.SarifIssuesProvider",
"ESLint")
.InFile(@"src\collections\list.cpp", 15)
.OfRule("no-unused-vars", new Uri("https://eslint.org/docs/rules/no-unused-vars"))
.WithPriority(IssuePriority.Error)
.Create());
}
}
}
}
57 changes: 57 additions & 0 deletions src/Cake.Issues.Sarif.Tests/Testfiles/eslint.sarif
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"version": "2.1.0",
"$schema": "http://json.schemastore.org/sarif-2.1.0-rtm.4",
"runs": [
{
"tool": {
"driver": {
"name": "ESLint",
"informationUri": "https://eslint.org",
"rules": [
{
"id": "no-unused-vars",
"shortDescription": {
"text": "disallow unused variables"
},
"helpUri": "https://eslint.org/docs/rules/no-unused-vars",
"properties": {
"category": "Variables"
}
}
]
}
},
"artifacts": [
{
"location": {
"uri": "file:///C:/dev/sarif/sarif-tutorials/samples/Introduction/simple-example.js"
}
}
],
"results": [
{
"level": "error",
"message": {
"text": "'x' is assigned a value but never used."
},
"locations": [
{
"physicalLocation": {
"artifactLocation": {
"uri": "file:///C:/dev/sarif/sarif-tutorials/samples/Introduction/simple-example.js",
"index": 0
},
"region": {
"startLine": 1,
"startColumn": 5
}
}
}
],
"ruleId": "no-unused-vars",
"ruleIndex": 0
}
]
}
]
}
Loading