Metrics analyzer for Razor: Lines of code are outside the range of the file
Closed this issue · 1 comments
martin-strecker-sonarsource commented
Community report:
https://community.sonarsource.com/t/java-lang-illegalargumentexception-line-575-is-out-of-range-for-file-xxx-file-has-386-lines/108740/15
The razor source generator of .Net SDK 9.0.100-preview.3.24204.13 produces a file with missing #line default
and #line hidden
directives for using
directives:
#line (1,2)-(2,1) "File.razor"
using System.Net.Http
#nullable disable
;
#nullable restore
Instead, the generated code should look like so:
#line (1,2)-(2,1) "File.razor"
using System.Net.Http
#line default
#line hidden
#nullable disable
;
#nullable restore
As a result, we count the ;
as code line but the mapping is beyond the length of the file if the using
is the only content of the file like in _Imports.razor
martin-strecker-sonarsource commented
How to fix:
We need to make sure, the range added here is within the document: