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

Metrics analyzer for Razor: Lines of code are outside the range of the file #9288

Closed
martin-strecker-sonarsource opened this issue May 16, 2024 · 1 comment · Fixed by #9299
Assignees
Labels
Area: C# C# rules related issues. Type: Bug Exceptions and blocking issues during analysis.
Projects
Milestone

Comments

@martin-strecker-sonarsource
Copy link
Contributor

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
Copy link
Contributor Author

How to fix:
We need to make sure, the range added here is within the document:

return Enumerable.Range(start, end - start + 1);

@github-actions github-actions bot added this to Review in progress in Best Kanban May 21, 2024
Best Kanban automation moved this from Review in progress to Validate Peach May 22, 2024
@costin-zaharia-sonarsource costin-zaharia-sonarsource moved this from Validate Peach to Done in Best Kanban May 22, 2024
@mary-georgiou-sonarsource mary-georgiou-sonarsource added this to the 9.25.1 milestone May 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: C# C# rules related issues. Type: Bug Exceptions and blocking issues during analysis.
Projects
Best Kanban
  
Done
Development

Successfully merging a pull request may close this issue.

4 participants