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

[BUG] cshtml formatter keeps adding blank lines #963

Closed
ysiivan opened this issue Feb 28, 2024 · 4 comments · Fixed by dotnet/razor#10802
Closed

[BUG] cshtml formatter keeps adding blank lines #963

ysiivan opened this issue Feb 28, 2024 · 4 comments · Fixed by dotnet/razor#10802
Assignees
Labels
area-razor bug Something isn't working
Milestone

Comments

@ysiivan
Copy link

ysiivan commented Feb 28, 2024

Describe the Issue

In some cases when saving (or anything that triggers formatting, I guess) a *.cshtml file in VS Code, blank lines are being added in some places with each save.
The user might not even notice that their file is growing. In my case, a fragment near the bottom of the page got blown so much that in a week or so the file grew by dozens of thousands of rows.

Appears to be a bug in the formatter that perhaps does not properly work with line endings.

Steps To Reproduce

VS Code on Windows working on code base with Unix line endings (LF).
The issue was not observed in Linux or in Windows when the file has Windows line endings {CRLF).
I have this near the end of one of my Razor pages:

    @if (Model.IsActive)
    {
        <button type="submit" class="btn btn-primary" asp-page-handler="Inactivate">Inactivate</button>
    }
    else
    {
        <button type="submit" class="btn btn-primary" asp-page-handler="Activate">Activate</button>
        <button type="submit" class="btn btn-primary" asp-page-handler="Save">Save</button>
    }
</form>

After one save, it looks like this

    @if (Model.IsActive)

    {
        <button type="submit" class="btn btn-primary" asp-page-handler="Inactivate">Inactivate</button>
    }

    else

    {
        <button type="submit" class="btn btn-primary" asp-page-handler="Activate">Activate</button>
        <button type="submit" class="btn btn-primary" asp-page-handler="Save">Save</button>
    }
</form>

After two saves:

    @if (Model.IsActive)



    {
        <button type="submit" class="btn btn-primary" asp-page-handler="Inactivate">Inactivate</button>
    }



    else



    {
        <button type="submit" class="btn btn-primary" asp-page-handler="Activate">Activate</button>
        <button type="submit" class="btn btn-primary" asp-page-handler="Save">Save</button>
    }
</form>

and so on

Expected Behavior

Blank lines should not be added. The formatter should work correctly with either LF or CRLF files regardless of the OS VS Code is being used on.

Environment Information

Windows 11

@ysiivan ysiivan added the bug Something isn't working label Feb 28, 2024
@microsoft microsoft deleted a comment from github-actions bot Mar 21, 2024
@phil-allen-msft phil-allen-msft added this to the June2024 milestone May 7, 2024
@phil-allen-msft phil-allen-msft modified the milestones: June2024, July2024 Jul 9, 2024
@ryzngard
Copy link
Member

@jordi1215 is this now fixed? I remember you had something similar....

@ryzngard ryzngard modified the milestones: July2024, Aug2024 Aug 12, 2024
@aktxyz
Copy link

aktxyz commented Aug 16, 2024

happens to me as well fyi ... and I like to auto format so I end up with a ton of empty lines usually after a @foreach() ...

any workarounds ? I have tried adding comments and poking at it but seems to add lines reliably !

@jordi1215 jordi1215 linked a pull request Sep 11, 2024 that will close this issue
@webreidi webreidi modified the milestones: Aug2024, Sept2024 Sep 26, 2024
@phil-allen-msft phil-allen-msft modified the milestones: Sept2024, Oct2024 Sep 26, 2024
@c8j
Copy link

c8j commented Oct 4, 2024

Still happening for me as well (only using the C# extension, without devkit) on my windows machine only (since I set it up to also use LF to be consistent with my linux machine)

@jordi1215
Copy link
Member

We believe that this issue was fixed with the C# VS Code extension version 2.49.25, released on October 8th 2024 (See PR: dotnet/razor#10802). If any of you experience the same or a similar issue, please let us know. Thanks!

@jordi1215 jordi1215 modified the milestones: Oct2024, Nov2024 Nov 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-razor bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants