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

Commit 645405b

Browse files
committed
Merge branch 'hotfix/0.9.1'
2 parents 7d098cf + 71c1780 commit 645405b

File tree

4 files changed

+58
-1
lines changed

4 files changed

+58
-1
lines changed

src/Cake.Issues.InspectCode.Tests/Cake.Issues.InspectCode.Tests.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@
1616

1717
<ItemGroup>
1818
<None Remove="Testfiles\inspectcode.xml" />
19+
<None Remove="Testfiles\WithoutLineButOffset.xml" />
1920
<None Remove="Testfiles\WithWikiUrl.xml" />
2021
</ItemGroup>
2122

2223
<ItemGroup>
2324
<EmbeddedResource Include="Testfiles\inspectcode.xml" />
25+
<EmbeddedResource Include="Testfiles\WithoutLineButOffset.xml" />
2426
<EmbeddedResource Include="Testfiles\WithWikiUrl.xml" />
2527
</ItemGroup>
2628

src/Cake.Issues.InspectCode.Tests/InspectCodeIssuesProviderTests.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,31 @@ public void Should_Read_Issue_Correct()
6262
.Create());
6363
}
6464

65+
[Fact]
66+
public void Should_Read_Issue_Without_Line_Correct()
67+
{
68+
// Given
69+
var fixture = new InspectCodeIssuesProviderFixture("WithoutLineButOffset.xml");
70+
71+
// When
72+
var issues = fixture.ReadIssues().ToList();
73+
74+
// Then
75+
issues.Count.ShouldBe(1);
76+
var issue = issues.Single();
77+
IssueChecker.Check(
78+
issue,
79+
IssueBuilder.NewIssue(
80+
@"Using directive is not required by the code and can be safely removed",
81+
"Cake.Issues.InspectCode.InspectCodeIssuesProvider",
82+
"InspectCode")
83+
.InProjectOfName("Project1")
84+
.InFile(@"Src\myfile.cs", 1)
85+
.OfRule("RedundantUsingDirective", new Uri("https://www.jetbrains.com/resharperplatform/help?Keyword=RedundantUsingDirective"))
86+
.WithPriority(IssuePriority.Warning)
87+
.Create());
88+
}
89+
6590
[Fact]
6691
public void Should_Read_Rule_Url()
6792
{
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- Generated by JetBrains Inspect Code 2021.1.3 -->
3+
4+
<Report ToolsVersion="211.0.20210525.205200">
5+
<Information>
6+
<Solution>Temp.sln</Solution>
7+
<InspectionScope>
8+
<Element>Solution</Element>
9+
</InspectionScope>
10+
</Information>
11+
<IssueTypes>
12+
<IssueType Id="RedundantUsingDirective" Category="Redundancies in Code" CategoryId="CodeRedundancy" Description="Redundant using directive" Severity="WARNING" WikiUrl="https://www.jetbrains.com/resharperplatform/help?Keyword=RedundantUsingDirective" />
13+
</IssueTypes>
14+
<Issues>
15+
<Project Name="Project1">
16+
<Issue TypeId="RedundantUsingDirective" File="Src\myfile.cs" Offset="0-48" Message="Using directive is not required by the code and can be safely removed" />
17+
</Project>
18+
</Issues>
19+
</Report>

src/Cake.Issues.InspectCode/InspectCodeIssuesProvider.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,18 @@ private static bool TryGetLine(XElement issue, out int line)
174174
var lineValue = lineAttr?.Value;
175175
if (string.IsNullOrWhiteSpace(lineValue))
176176
{
177-
return false;
177+
var offsetAttr = issue.Attribute("Offset");
178+
179+
var offsetValue = offsetAttr?.Value;
180+
if (string.IsNullOrWhiteSpace(offsetValue))
181+
{
182+
return false;
183+
}
184+
185+
// There are cases where InspectCode reports an offset, but no line.
186+
// In this case we will assume line 1.
187+
line = 1;
188+
return true;
178189
}
179190

180191
line = int.Parse(lineValue, CultureInfo.InvariantCulture);

0 commit comments

Comments
 (0)