Skip to content
This repository was archived by the owner on Apr 13, 2024. It is now read-only.

Commit 6ad8b57

Browse files
committed
Add test case for parsing files generated by ESLint
1 parent 70ded77 commit 6ad8b57

File tree

3 files changed

+86
-0
lines changed

3 files changed

+86
-0
lines changed

src/Cake.Issues.Sarif.Tests/Cake.Issues.Sarif.Tests.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,14 @@
1313
<CodeAnalysisRuleSet>..\Cake.Issues.Sarif.Tests.ruleset</CodeAnalysisRuleSet>
1414
</PropertyGroup>
1515

16+
<ItemGroup>
17+
<None Remove="Testfiles\eslint.sarif" />
18+
</ItemGroup>
19+
1620
<ItemGroup>
1721
<EmbeddedResource Include="Testfiles\cake.issues.reporting.sarif.sarif" />
1822
<EmbeddedResource Include="Testfiles\comprehensive.sarif" />
23+
<EmbeddedResource Include="Testfiles\eslint.sarif" />
1924
<EmbeddedResource Include="Testfiles\minimal.sarif" />
2025
<EmbeddedResource Include="Testfiles\recommended-with-source.sarif" />
2126
<EmbeddedResource Include="Testfiles\recommended-without-source.sarif" />

src/Cake.Issues.Sarif.Tests/SarifIssuesProviderTests.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,30 @@ public void Should_Read_Issue_Correct_For_File_Generated_By_CakeIssuesReportingS
173173
.WithPriority(IssuePriority.Warning)
174174
.Create());
175175
}
176+
177+
[Fact]
178+
public void Should_Read_Issue_Correct_For_File_Generated_By_EsLint()
179+
{
180+
// Given
181+
var fixture = new SarifIssuesProviderFixture("eslint.sarif");
182+
183+
// When
184+
var issues = fixture.ReadIssues().ToList();
185+
186+
// Then
187+
issues.Count.ShouldBe(1);
188+
var issue = issues.Single();
189+
IssueChecker.Check(
190+
issue,
191+
IssueBuilder.NewIssue(
192+
"'x' is assigned a value but never used.",
193+
"Cake.Issues.Sarif.SarifIssuesProvider",
194+
"ESLint")
195+
.InFile(@"src\collections\list.cpp", 15)
196+
.OfRule("no-unused-vars", new Uri("https://eslint.org/docs/rules/no-unused-vars"))
197+
.WithPriority(IssuePriority.Error)
198+
.Create());
199+
}
176200
}
177201
}
178202
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{
2+
"version": "2.1.0",
3+
"$schema": "http://json.schemastore.org/sarif-2.1.0-rtm.4",
4+
"runs": [
5+
{
6+
"tool": {
7+
"driver": {
8+
"name": "ESLint",
9+
"informationUri": "https://eslint.org",
10+
"rules": [
11+
{
12+
"id": "no-unused-vars",
13+
"shortDescription": {
14+
"text": "disallow unused variables"
15+
},
16+
"helpUri": "https://eslint.org/docs/rules/no-unused-vars",
17+
"properties": {
18+
"category": "Variables"
19+
}
20+
}
21+
]
22+
}
23+
},
24+
"artifacts": [
25+
{
26+
"location": {
27+
"uri": "file:///C:/dev/sarif/sarif-tutorials/samples/Introduction/simple-example.js"
28+
}
29+
}
30+
],
31+
"results": [
32+
{
33+
"level": "error",
34+
"message": {
35+
"text": "'x' is assigned a value but never used."
36+
},
37+
"locations": [
38+
{
39+
"physicalLocation": {
40+
"artifactLocation": {
41+
"uri": "file:///C:/dev/sarif/sarif-tutorials/samples/Introduction/simple-example.js",
42+
"index": 0
43+
},
44+
"region": {
45+
"startLine": 1,
46+
"startColumn": 5
47+
}
48+
}
49+
}
50+
],
51+
"ruleId": "no-unused-vars",
52+
"ruleIndex": 0
53+
}
54+
]
55+
}
56+
]
57+
}

0 commit comments

Comments
 (0)